Hexo theme: icarus| Highly personalize it© ppoffice

Hexo theme: icarus| Highly personalize it

Hexo Theme: Icarus

GitHub: Ruipeng Zhang
Document: PPOffice Blog

Current Version: 4.0.0

Install

sudo apt upgrade node

hexo init /media/ken/Data/Github/hexo-icarus
cd /media/ken/Data/Github/hexo-icarus
sudo npm install -g hexo-cli
npm install

npm install hexo-theme-icarus
hexo config theme icarus
hexo server

Error Message

(node:19025) ExperimentalWarning: The fs.promises API is experimental
INFO  =======================================
██╗ ██████╗ █████╗ ██████╗ ██╗   ██╗███████╗
██║██╔════╝██╔══██╗██╔══██╗██║   ██║██╔════╝
██║██║     ███████║██████╔╝██║   ██║███████╗
██║██║     ██╔══██║██╔══██╗██║   ██║╚════██║
██║╚██████╗██║  ██║██║  ██║╚██████╔╝███████║
╚═╝ ╚═════╝╚═╝  ╚═╝╚═╝  ╚═╝ ╚═════╝ ╚══════╝
=============================================
INFO  === Checking package dependencies ===
ERROR Package bulma-stylus is not installed.
ERROR Package hexo-renderer-inferno is not installed.
ERROR Please install the missing dependencies your Hexo site root directory:
ERROR npm install --save bulma-stylus@0.8.0 hexo-renderer-inferno@^0.1.3
ERROR or:
ERROR yarn add bulma-stylus@0.8.0 hexo-renderer-inferno@^0.1.3

how to solve

npm install bulma-stylus
npm install hexo-renderer-inferno
hexo config theme icarus
hexo server

Error Message

ERROR Package bulma-stylus's version (0.9.1) does not satisfy the required version (0.8.0).

how to solve

npm install bulma-stylus@0.8.0
hexo config theme icarus
hexo server

Stylize

After you run hexo new Notes, a file nameds as Notes.md would be created in source/_posts. The head a few lines would be exactly as you stored in ./scaffolds/post.md. As a result, you just need to change the words in that file to create your own model for all new posts. For example, I’ll add some new features and a style feature for text block by change this file.

post.md
---
title:
ytitle:
date: {{ date }}
toc: true
description:
url: {{ title }}
excerpt:
tags:
category:
cover:
thumbnail:
covercopy: '© Karobben'
priority: 10000
---


<style>
pre {
background-color:#38393d;
color: #5fd381;
}
</style>

icarus: To Do List

Before we started, there are a few other excellent posts I’d like to share with:
iMaeGoo 2020: 活用 Bulma 美化 Icarus 文章

Anyway, let’s follow the document first:
Document: PPOffice Blog


Optional:

_config.icarus.yml

RSS

  • a, p, RSS span
Terminal
# install the RSS plugin
npm install hexo-generator-feed
# Generate RSS XML file
hexo g

It indicates you made it if you can see the code below:

...
INFO  Generated: 2020/06/10/R/WGCNA/index.html
INFO  Generated: atom.xml
INFO  Generated: 2019/08/13/R/edgeR/index.html
INFO  Generated: content.json
INFO  690 files generated in 21 s

Then, adding the path into _config.icarus.yml

_config.icarus.yml
social_links:
RSS:
icon: fas fa-rss
url: 'atom.xml'

Thumbnail & Cover[1]

thumbnail is the image show in recent
cover is the image show in main page

post.md
---
cover: '/img/123.png'
thumbnail: '/img/123.png'
---

Index

post.md
toc: true
---

Read More Button

post.md
---
title: '123'
excerpt: "This post is for recording..."
---

Comment[2]

comment:
    type: utterances
    repo: Your-GitHub-Username/Your-Public-Repo-Name
    issue_term: pathname        # Required if issue_number is not set
    issue_number: 100           # Required if issue_term is not set. Every post can be mapped to a separate, manually-created GitHub issue.
    label: some-issue-label     # Optional
    theme: github-light         # Optional
    crossorigin: anonymous

log, favicon, and avatar

log is the img line with the action bar

_config.icarus.yml
logo: # image of your logo

head:
favicon: # image for web tag logo

avatar: # image for profile

Share

the easiest way:

_config.icarus.yml
share:
type: sharejs

baidu_analytics[3]

_config.icarus.yml
plugins:
baidu_analytics:
tracking_id: 3f06f2b************

Anchor Sidebar

_config.icarus.yml
sidebar:
left:
sticky: true
right:
sticky: true

Math Function

_config.icarus.yml
mathjax: true

Math Function Font Size

The default size of the math function is the same size as the article which makes the functions are hard to distinguish from the main page.

The easiest method to alter their font-size is adding something if themes/icarus/include/style/article.styl:

PS:

  • .mjx-chtml works on $$ (double) quoted functions only.
  • .mjx-math works on both $$ and $ quoted function.
article.styl
article
&.article
.content
word-wrap: break-word
font-size: $article-font-size
+ span
+ .mjx-chtml
+ overflow: auto
+ max-width: 100%
+ font-size: 1.5 em
+ z-index: 999
+ .mjx-math
+ font-size: 1.1 em
+ font-weight: 700
+ color: SteelBlue
+ background-color:white;
Default Style Changed Style
Hexo Math function Hexo Math function

Admonition

reference: lxl80/hexo-admonition

  1. install the plugin:
npm install hexo-admonition --save
  1. add the codes at the end of themes/icarus/include/style/article.styl:
article.styl
.admonition {
margin: 1.5625em 0;
padding: .6rem;
overflow: hidden;
font-size: 1rem;
page-break-inside: avoid;
border-left: .3rem solid #42b983;
border-radius: .3rem;
box-shadow: 0 0.1rem 0.4rem rgba(0,0,0,.05), 0 0 0.05rem rgba(0,0,0,.1);
background-color: #fafafa;
}

p.admonition-title {
position: relative;
margin: -.6rem -.6rem .8em -.6rem !important;
padding: .4rem .6rem .4rem 2.5rem;
font-weight: 700;
background-color:rgba(66, 185, 131, .1);
}

.admonition-title::before {
position: absolute;
top: .9rem;
left: 1rem;
width: 12px;
height: 12px;
background-color: #42b983;
border-radius: 50%;
content: ' ';
}

.info>.admonition-title, .todo>.admonition-title {
background-color: rgba(0,184,212,.1);
}

.warning>.admonition-title, .attention>.admonition-title, .caution>.admonition-title {
background-color: rgba(255,145,0,.1);
}

.failure>.admonition-title, .missing>.admonition-title, .fail>.admonition-title, .error>.admonition-title {
background-color: rgba(255,82,82,.1);
}

.admonition.info, .admonition.todo {
border-color: #00b8d4;
}

.admonition.warning, .admonition.attention, .admonition.caution {
border-color: #ff9100;
}

.admonition.failure, .admonition.missing, .admonition.fail, .admonition.error {
border-color: #ff5252;
}

.info>.admonition-title::before, .todo>.admonition-title::before {
background-color: #00b8d4;
border-radius: 50%;
}

.warning>.admonition-title::before, .attention>.admonition-title::before, .caution>.admonition-title::before {
background-color: #ff9100;
border-radius: 50%;
}

.failure>.admonition-title::before,.missing>.admonition-title::before,.fail>.admonition-title::before,.error>.admonition-title::before{
background-color: #ff5252;;
border-radius: 50%;
}

.admonition>:last-child {
margin-bottom: 0 !important;
}
  1. Use:
hexo clean
hexo s -g
post.md
!!! note Hexo-admonition 插件使用示例
这是基于 hexo-admonition 插件渲染的一条提示信息。类型为 note,并设置了自定义标题。

提示内容开头留 4 个空格,可以有多行,最后用空行结束此标记。

!!! warning
这是一条采用默认标题的警告信息。
<pre>
Warning messages
</pre>

!!! failure "嵌套链接及引用块"
欢迎访问我的博客链接:[悟尘纪](https://www.lixl.cn)

>这里嵌套一行引用信息。


!!! infor "嵌套链接及引用块"
```bash
echo hello world
``\`

Hexo-admonition 插件使用示例

这是基于 hexo-admonition 插件渲染的一条提示信息。类型为 note,并设置了自定义标题。

提示内容开头留 4 个空格,可以有多行,最后用空行结束此标记。

warning

这是一条采用默认标题的警告信息。

Warning messages

嵌套链接及引用块

欢迎访问我的博客链接:悟尘纪

这里嵌套一行引用信息。

r 嵌套链接及引用块

echo hello world

CC block

You can’t alter the infor from _config.icarus.yml because everything is recorded in _congig.yml

_congig.yml
title: Karobben
subtitle: ''
description: ''
keywords: Biology, Data Science, Bioinformatics
author: Karobben
language: en
timezone: ''
url: 'https://karobben.github.io/'

You may can’t find the hexo-theme-icarus in your theme directory. So, for editing the role module, we can editing them in node_modules/hexo-theme-icarus

FlowChart & Mermaid

FlowChart and Mermaid: link

For icarus, hexo document didn’t give the resolution for jsx file.
So, I insert the <script src="https://unpkg.com/mermaid@8.8.4/dist/mermaid.min.js"></script> directly in themes/icarus/layout/common/scripts.jsx

scripts.jsx
return <Fragment>
<script src={cdn('jquery', '3.3.1', 'dist/jquery.min.js')}></script>
<script src={cdn('moment', '2.22.2', 'min/moment-with-locales.min.js')}></script>
{clipboard && <script src={cdn('clipboard', '2.0.4', 'dist/clipboard.min.js')} defer></script>}
<script dangerouslySetInnerHTML={{ __html: `moment.locale("${language}");` }}></script>
<script dangerouslySetInnerHTML={{ __html: embeddedConfig }}></script>
<script src={url_for('/js/column.js')}></script>
<Plugins site={site} config={config} page={page} helper={helper} head={false} />
<script src={url_for('/js/main.js')} defer></script>
// mermaid script
<script src="https://unpkg.com/mermaid@8.8.4/dist/mermaid.min.js">
</script>
// mermaid script ends
</Fragment>;
}

It’s not the best resolution, but it works.
And a problem is it can’t show the whole word if the word is long.

Busuanzi

You can try to enable the busuanzi plugin in _congig.icarus.yml. But I have no idea why that it doesn’t work all the time. But it still doen’t work at first. Thanks for BoyInTheSun[4]. It seams like it conflicted to lived2d plugin. By solving this problem, the best solution is download the script to local and alter the script.

Before you do this, make sure you have called the busuanzi: false in _congig.icarus.yml or it won’t work.

Insert latest script inner the <div class="level-start"> tags at /themes/icarus/layout/common/footer.ejs file

The latest script you can find at BUSUANZI

/themes/icarus/layout/common/footer.jsx
<script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
<span id="busuanzi_container_site_pv">本站总访问量<span id="busuanzi_value_site_pv"></span>次</span>

Go check the raw codes. if it shows that <span id="busuanzi_container_site_uv" style="display: none;"> and nothing show at all, it means some plugin conflicted to it. You can fix this by following another post.

Visitors for each post[5]

This script is based on the Busaunzi script below
After you insert the codes below appropriately, we can add the codes below inner <div class="level-left"> in /themes/icarus/layout/common/article.jsx

/themes/icarus/layout/common/article.jsx
{/* counts of this passage*/}
<i class="far fa-eye"></i>
<span>&nbsp;</span>
<span id="busuanzi_container_page_pv" style="display: inline;">
<span id="busuanzi_value_page_pv">0</span>&nbsp;
</span>
{/* counts of this passage Done*/}

Result:
yTIvdK.md.png

add a covercopy tag in the md header

***.md
title: "Hexo theme: icarus"
date: "2021/02/11"
toc: true
covercopy: '© ppoffice'

Then, insert the codes below in card-image tag in themes/icarus/layout/common/article.jsx file as it’s show.

<span style="position: absolute; bottom: 0; right: 0; padding-right:3px; padding-left:4px; background-color: rgba(255, 255, 255, 0.6)" class="ccopy" dangerouslySetInnerHTML={{ __html: index && page.covercopy ? page.covercopy : page.covercopy }}></span>

My example:

article.jsx
{cover ? <div class="card-image">
{index ? <a href={url_for(page.link || page.path)} class="image is-7by3">
<img class="fill" src={cover} alt={page.title || cover} />
</a> : <span class="image is-7by3">
<img class="fill" src={cover} alt={page.title || cover} />
</span>}
<span style="position: absolute; bottom: 0; right: 0; padding-right:3px; padding-left:4px; background-color: rgba(255, 255, 255, 0.6)" class="ccopy" dangerouslySetInnerHTML={{ __html: index && page.covercopy ? page.covercopy : page.covercopy }}></span>
</div> : null}

和瓦雀共存

瓦雀需要summary.md做index界面, 需要(可選) layout.md 做統一落款, 用 yuque.yml 做配置文件

如果直接使用, 則會出現如下圖片情況:
yHIWZt.md.png

這些文件都會被渲染且置頂(因爲沒有時間). 非常難受.
查閱後可知, hexo 自帶的 skip_render 可以完美解決此方案. 因此, 只需要在_config.yml 中, 添加通配字符, 即可解決次問題.

_config.yml
skip_render:
- _posts/**/**.yml
- _posts/**/layout.md
- _posts/**/summary.md
- _posts/**/index.md

之後, 記得 清除緩存, 再查看效果

hexo clean
hexo s --watch

用 python 腳本輔助更新語雀筆記: 腳本鏈接

The size of the default logo was too small to fit the cell phone page.
So, I tried to alter the height from the raw code. But nothing happened. By retrieving the element one by one, you’ll finally find that it sited an argument of max-height: 1.75rem for this class. The quick solution is to set a new value for max-height in themes/icarus/include/style/navbar.styl.(PS: I set it equals 3.8rem)
Bsides, I also commented the padding and margin to make the header tight.

themes/icarus/include/style/navbar.styl
.navbar-item
display: flex
align-items: center
/*padding: $navbar-item-padding-v $navbar-item-padding-h*/
/*margin: $navbar-item-margin-v $navbar-item-margin-h*/
© Karobben
Before
© Karobben
After
© Karobben
The Final

And this how I find everything.

By checking the raw codes, we can know the logo was:

<a class="navbar-item navbar-logo" href="/">
<img src="/Karobben_logo_horizontal_800.png" alt="Karobben" height="28">
</a>

The class is navbar-logo.
So, by searching this class, we can located it in

grep -s "navbar-logo" $(find themes/icarus)| awk -F":" '{print $1}'
themes/icarus/include/style/navbar.styl
themes/icarus/layout/common/navbar.jsx

By checking the themes/icarus/layout/common/navbar.jsx, there are nothing we can do.

<a class="navbar-item navbar-logo" href={siteUrl}>
{navbarLogo}
</a>

By checking the themes/icarus/include/style/navbar.styl, we now know,

.navbar-logo
img
max-height: $logo-height

Let’s continue to retrive the logo-height

grep -s "logo-height" $(find themes/icarus)| awk -F":" '{print $1}'
themes/icarus/include/style/base.styl
themes/icarus/include/style/footer.styl
themes/icarus/include/style/navbar.styl

Finally, you’ll find this in themes/icarus/include/style/base.styl:

$logo-height ?= 1.75rem

Stick the togs (headers/CATALOGUE)

In version V4.0, the scripts in themes/icarus/layout/widget are all gone except profile.jsx. I have no idea why. But by reading the issue #740, I thought maybe I can try to bring it back to the widget. When I firstly copy toc.jsx from hexo-component-inferno, it runs incorrectly:

ERROR {
  err: Error: Cannot find module '../../util/cache'
  Require stack:
  - /media/ken/Data/Github/hexo-icarus/themes/icarus/layout/widget/toc.jsx
  - /media/ken/Data/Github/hexo-icarus/node_modules/hexo-renderer-inferno/lib/compile.js
  - /media/ken/Data/Github/hexo-icarus/node_modules/hexo-renderer-inferno/index.js
      at Function.Module._resolveFilename (node:internal/modules/cjs/loader:923:15)

Obviously, we lack a model named cache.js
So, I checked the repository again and found the util/cache.js at here

Instead of making another directory, I placed the cache.js to themes/icarus/scripts/cache.js and change the path in themes/icarus/layout/widget/toc.jsx

Here’s how I achieved it:

  1. copy the cache.js from GitHub to themes/icarus/scripts/cache.js
  2. copy the toc.jsx from GitHub to themes/icarus/layout/widget/toc.jsx
  3. Replace the codes:
    toc.jsx
    - const { cacheComponent } = require('../../until/cache');
    + const { cacheComponent } = require('../../scripts/cache');
  4. Adding the is-sticky in to the class[7]:
    toc.jsx
    - <div class="card widget" id="toc" data-type="toc">
    + <div class="card widget is-sticky" id="toc" data-type="toc">
BASH
hexo clean
hexo g

Change the “latest posts” to “Recommended Post”

One of the sidebars is showing the latest posts. But, yeah, it is unnecessary since everything shows on the home page already. But it’ll be a good place to place your most recommended or valuable posts. By doing that, we need to make a few changes.

For old version[8]:

  1. Find \icarus\layout\widget\recent_posts.ejs:
    Change the code 1 to code 2

    ejs recent_posts.ejs
    - <% site.posts.sort('date', -1).limit(5).each(post => { %>
    + <% site.posts.sort('priority', -1).limit(5).each(post => { %>
  2. Change the name of the block: Change the name in language is fine

    en.yml
    - recents: 'Recents'
    + recents: 'Recommend'
  3. Adding the priority at the head of the posts.

    post.md
    ---
    title: "Hexo theme: icarus"
    date: "2021/02/11"
    toc: true
    + priority: 1
    ---

For Version 4.0

As is the situation in above, we need to cp the files, first.

  1. copy the article_media.jsx from GitHub to layout/common/article_media.jsx
  2. copy the recent_posts.jsx GitHub to themes/icarus/layout/widget/recent_posts.jsx
  3. Alter the require path:
    recent_posts.jsx
    - const { cacheComponent } = require('../../until/cache');
    + const { cacheComponent } = require('../../scripts/cache');
  4. Alter the codes similar like the old version:
    recent_posts.jsx
    - .sort('date', -1)
    + .sort('priority')
  5. Adding priority as same as above:
    post.md
    ---
    title: "Hexo theme: icarus"
    date: "2021/02/11"
    toc: true
    + priority: 1
    ---
Attention:

It might not work if you didn’t add priority to most of the posts and this takes me a few hours to found it out…

You can use sed to add the priority to all posts:

sed -i  '/^thumbnail:/a\priority: 10000'  $(find source/_posts/ -name "*.md")

Make sure that the ^thumbnail: is unique to each post.

hexo clean
hexo g

Keep _post directory free with suspicious files

Highlight/Mark

In markdown, we can using the == to mark words or sentences.
But the the default mark would be rendering to yellow: Highlight
And my target is change it to Highlight

Open include/style/article.styl:

article.styl
h5
font-size: 1em

+ mark
+ background-color: salmon
+ padding: .2em
+ border-radius: .4em
BASH
hexo clean
hexo g

max height for <pre> and <code>

The passage would be looked untidy if the code block or the <pre> block is too long. So, assign the max-height is a good choise.

Since code was embedded in pre, we just need to change pre.

Open include/style/article.styl:

article.styl
pre
font-size: .85em
+ max-height: 30em
BASH
hexo clean
hexo g

Abbreviation style

Though abbreviation is convenient in markdown, it is hard to achive in cellphone since there are no suspend events for touch screen. Adding an click event could make it friendly to cellphone users.

Open include/style/article.styl:

article.styl
abbr
position: relative;
color: seagreen

abbr:active::before
content: attr(title);
white-space: nowrap;
round: 90;
position: absolute;
top: 100%;
background-color: #000000;
color: #fff;
border-radius: 5px;
opacity:0.8;
padding-left: 10px;
padding-right: 10px;
z-index: 999

Abbreviation grammar in markdown:

post.md
*[HB]: hemoglobin
HB

HB

BASH
hexo clean
hexo g

Visitor-traffics map

Pick a Visitor traffics map server you like: link

Personally, I’d like to adding it at the end of the profile:
so, the code would be inserted into layout/widget/profile.jsx around line-77.

profile.jsx
        </div> : null}
{socialLinks ? this.renderSocialLinks(socialLinks) : null}
</div>
+
+ <div class= "card">
+ <script type="text/javascript" src="//rf.revolvermaps.com/0/0/7.js?i=${your ID}&m=0c&c=f03b11&cr1=ffffff&sx=0&cw=ffffff&cb=3472cd" async="async"></script>
+ </div>
+
</div>;
}
}

Widget Graphviz

GitHub document

  • Install
npm install --save hexo-graphviz
# npm install https://github.com/dwatow/hexo-filter-viz.git
  • Adding the script

Added this to layout/common/footer.jsx before </footer>;

footer.jsx
    {/*graphviz script start*/}
<script src='https://cdnjs.cloudflare.com/ajax/libs/viz.js/1.7.1/viz.js'></script>
{/*graphviz script end*/}
</footer>;
  • (Optional) set the max-width
    If the width of Graphviz is long, it may exceed out of the border.
    include/style/article.styl
article.styl
&.article
.article-meta, .article-tags
color: $text-light

.article-meta
overflow-x: auto
margin-bottom: .5rem

.article-more
@extend .button.is-light

.content
word-wrap: break-word
font-size: $article-font-size

+ svg
+ max-width : 100%;

include the code below in graphviz

digraph F {
    rankdir = LR;
    edge [style=solid];
    node [style=filled, font=Courier];

    subgraph M {
        rank = same;
        Start [label = "Lamp doesn't work", shape = box, fillcolor = "#FF0000" ];
        End   [label = "Repair lamp"      , shape = box, color = coral];

        Con1 [label = "Lamp plugged in?", shape = diamond, color = green, size = 3];
        Con2 [label = "Bulb burned out?", shape = diamond, color = green, size = 3];
    }

    subgraph C {
        rank = same;
        RB [label = "Replace bulb", shape = box, color = deepskyblue1];
        AP [label = "Plug in lamp", shape = box, color = deepskyblue1];
    }

    Start -> Con1;
    Con1 -> AP   [label = "No"];
    Con1 -> Con2 [label = "Yes"];

    Con2 -> RB  [label = "Yes"];
    Con2 -> End [label = "No"];

    AP -> End
    RB -> End
}

Strike Style

Open include/style/article.styl:

article.styl
h5
font-size: 1em

+ s
+ color: #00CD66
BASH
hexo clean
hexo g

Giscus

Origin blog: Yury Zhauniarovich

  1. Create public repository in your github (like ‘Giscus’)

Pre style

Add the codes below in each of md file

<style>
pre {
background-color:#38393d;
color: #5fd381;
}
</style>

<pre>
Pre block presentation
Just love this style
</pre>
Pre block presentation
Just love this style

  1. weixin_30300225, 2019: 安装配置hexo icarus主题配置 ↩︎

  2. PPOffice, 2017: Icarus User Guide - Comment Plugins ↩︎

  3. PPOffice, 2016: Icarus用户指南 - 网站分析插件 ↩︎

  4. BoyInTheSun, 2020: 解决live2d看板娘和busuanzi不蒜子计数冲突 ↩︎

  5. 摆柿阔落, 2019: Hexo | 两个你可能会用到的icarus主题配置 ↩︎

  6. 开着拖拉机的梦想家, 2016: HTML让文字在图片上显示 ↩︎

  7. Andy Cen, 2020: Hexo-Icarus主题配置建议 ↩︎

  8. somebody, 2019: hexo主题Icarus浅度修改教程 ↩︎

Hexo theme: icarus| Highly personalize it

https://karobben.github.io/2021/02/11/Blog/hexo_icarus/

Author

Karobben

Posted on

2021-02-11

Updated on

2023-06-06

Licensed under

Comments