Personal blog repo using hexo-butterfly-theme as submodule
npm install hexo-cli -g
hexo init blog-repo
cd blog-repo
git init
git branch -m master main
git remote add origin https://github.com/extreme-rearranger/blog-repo.git
git add .
git commit -m "initialize hexo blog"
git push origin main
git submodule add -b own-blog https://github.com/ex-rearranger/hexo-theme-butterfly.git themes/butterfly
git add .
git commit -m "add butterfly submodule"
git push origin main
npm un hexo-renderer-marked --save
npm un hexo-renderer-kramed --save
npm install hexo-renderer-markdown-it --save
npm install katex @renbaoshuo/markdown-it-katex --save
markdown:
plugins:
- '@renbaoshuo/markdown-it-katex'
npm install hexo-butterfly-tag-plugins-plus --save
# tag-plugins-plus
# see https://akilar.top/posts/615e2dec/
tag_plugins:
enable: true # 활성화
priority: 5 # 필터 우선 순위
issues: false # issues 라벨 활성화
link:
placeholder: /img/no-image.png #link_card 라벨의 기본 이미지
CDN:
anima: https://npm.elemecdn.com/[email protected]/lib/assets/font-awesome-animation.min.css #动画标签anima的依赖
jquery: https://npm.elemecdn.com/[email protected]/dist/jquery.min.js #issues标签依赖
issues: https://npm.elemecdn.com/[email protected]/lib/assets/issues.js #issues标签依赖
iconfont: //at.alicdn.com/t/font_2032782_8d5kxvn09md.js #参看https://akilar.top/posts/d2ebecef/
carousel: https://npm.elemecdn.com/[email protected]/lib/assets/carousel-touch.js
tag_plugins_css: https://npm.elemecdn.com/[email protected]/lib/tag_plugins.css
npm install hexo-wordcount --save
In my blog, the basic goal was to make English and Korean cross-support possible.
So I used the 'hexo-generator-i18n' plug-in.
In addition, many scripts using '_p()' have been modified to make the default language page (e.g., about.html) common to all languages.
By doing this, posts set in the 'default' language can alternately display both languages through the right side button, and furthermore, they are accessible to all archive/tags/categories regardless of language.
npm install hexo-generator-i18n --save
- get
i18n.js
,rfc5646.js
, and10_i18n.js
files from hexo-theme-minos'. - Then add the three files into
butterfly/layout/includes/scripts
.
I add directory namecustom_helpers
to distinguish with original files. - In
10_i18n.js
,categories()
andtags()
helpers should be all comment out since the functions don't work in this theme. - Instead, I made
tagclouds()
andlist_categories()
helpers by referring to the two. - Therefore, the final file structure is as follows:
...
├── scripts/
│ ├── custom_helpers
│ │ ├── 10_i18n.js # from hexo-theme-minos (except categories() and tags() helpers)
│ │ ├── i18n.js # from hexo-theme-minos
│ │ │ (i've changed isDefaultLanguage() and getDisplayLanguage() a little bit)
│ │ ├── listcategories.js
│ │ ├── rfc5646.js # from hexo-theme-minos
│ │ └── tagcloud.js
...
- Can use more than two languages though I used two.
language:
- default
- en
- ko
language_default: default
i18n_dir: :lang
i18n: # hexo-generator-i18n settings
type:
# - page # if active, then page_title, ko/page_title, en/page_title are all available with the same content
# - post # if active, then posts/:title, en/posts/:title, ko/posts/:title are all avaliable (this is not recommended since :title already contains language information)
generator: # all inactive since every helpers is defined in 10_i18n.js
# - archive
# - category
# - tag
# - index
default.yml
should contains all languages as the first level key.- I copied and pasted the contents of
en.yml
andko.yml
todefault.yml
.
Then, added theen
andko
keys in the first level.
- In this theme, the
_p()
function is used to get the language-specific content. - Since I want to use all language contents in the default language page, I added the language as prefix to the parameter of
_p()
function. - For instance, if it had previously been written as
_p('page_title')
, then I changed it to_p('en.page.title')
and_p('ko.page.title')
when the language is set to default. - In this way, the default language page can display both languages alternately if click the language transition button.
- It was a lot of work since i never studied js, pug, and any other front-end languages before.
- So the code might be a little bit messy, but it works pretty well. (maybe haha)
- In the theme, the language-related tags are used to display the language-specific content.
- For instance,
div
is changed todiv(div(lang-type='relative' language='en')
when the content is written in English.
- I use LocalSearch in my blog, so I changed the
source/js/search/local-search.js
to support multilingual. - Since the language information is initially not in
hexo-generator-searchdb
library,
I added the language information to the search DB.
(source/js/custom/hexo-generator-searchdb-custom
) - The search result is displayed in the alternative language when the language is changed
- Also, I add tags and categories to be searched
- The search result is sorted with weighted score of match count
(1000: language > 3: title > 2: categories, tags > 1: content)
- The search result is sorted with weighted score of match count
- In the theme, the
GLOBAL_CONFIG
is used to store the global variables that is used in the js during runtime. - I changed all the
GLOBAL_CONFIG
variables and related functions to support multilingual. - The changed files are below:
layout/includes/head/config.pug
layout/includes/mixins/post-ui.pug
layout/includes/third-party/search/*
source/js/search/algolia.js
source/js/custom/hexo-generator-searchdb-custom/dist/local-search.js
- This is the cusomized version of
source/js/search/local-search.js
- This is the cusomized version of
source/js/custom/change_lang.js
source/js/utils.js
(change diffDate() to support multilingual)source/js/main.js
(change all the text that using GLOBAL_CONFIG to support multilingual)
- Archive Length Helper (
findArchiveLength.js
)- Get archive length in multilingual manner
- For example, the posts in Korean will be dropped when the page language is set to English.
- Language Transition Button on rightside (
change_lang.js
, ...)- If the page language is set to default, then the button changes the text language alternately.
- If the page language is set to specific language, then the site will be redirected to the same page in the alternative language.
- Tag Cloud Helper (
tagcloud.js
)/en/tags/
and/ko/tags/
are available
- List Categories Helper (
listcategories.js
)/en/categories/
and/ko/categories/
are available
- Menu and Navigation
- Some site url changes automatically according to the page language
- For example,
/en/archive/
changes to/ko/archive/
when the language is changed
- Index Page with Multilingual Support (see index helper in
10_i18n.js
)index.html
show all postsen/index.html
show only English postsko/index.html
show only Korean posts
- Aside (Recent Posts, Categories, Tags, Blog Info, Archives) (
aside_categories.js
,aside_archives.js
, ...)- All the aside contents are available in multilingual manner
- If Language Transition Button is clicked, then the aside contents will be changed to the alternative language
- Search (
source/js/custom/hexo-generator-searchdb-custom
)- The search DB is generated in multilingual manner
- The search result is displayed in the alternative language when the language is changed
- Also, I add tags and categories to be searched
- The search result is sorted with weighted score of count (3: title > 2: categories, tags > 1: content)