Skip to content

Instantly share code, notes, and snippets.

@Yoxem
Last active July 29, 2018 16:15
Show Gist options
  • Save Yoxem/99f54b4868fef82e3cc726a422f5506c to your computer and use it in GitHub Desktop.
Save Yoxem/99f54b4868fef82e3cc726a422f5506c to your computer and use it in GitHub Desktop.
The script that I used with Hexo / 我使用於 Hexo 的 Script
/*
footnote.js: A filter for Hexo to generate footnotes. Place this file in /scripts/footnote.js.
========================================================================
Author: kuanyui(azazabc123[at]g~~~m~~~a~~~i~~~l[dot]com), Yoxem (yoxem.tem98[ A T ]nctu.edu.tw)
Date: 20180730
License: WTFPL 1.0
========================================================================
The following string in article
{fn|I'm the a lot lot of content.}
Will be converted into
<sup><a id="fnr.1" class="footref" href="#fn.1" name="fnr.1">1</a></sup>
And the following block will be added in the bottom of the article.
<div id="footnotes">
<h2 class="footnotes">Footnote</h2>
<div id="text-footnotes">
<div class="footdef"><sup><a id="fn.1" name="fn.1" class="footnum" href="#fnr.1">1</a></sup> <p class="footpara">I'm the a lot lot of content.</p></div>
<div class="footdef"><sup><a id="fn.2" name="fn.2" class="footnum" href="#fnr.2">2</a></sup> <p class="footpara">I'm the second content2</p></div>
...
</div>
</div>
Adding following CSS into your site is recommended:
.footpara {
display: inline;
margin-left: 5px;
}
*/
var lang = {"en_US": "Footnotes", "zh_TW": "腳註", "ja_JP": "脚注", "zh_CN": "脚注", "nan": "注跤 [tsù-kha]"};
if (lang[hexo.config.language]) {
var fnName = lang[hexo.config.language];
} else {
var fnName = "註腳";
}
hexo.extend.filter.register('pre', function(data, callback) {
var num = 0;
var footContent = "";
var RE = new RegExp('\\{fn\\|(.+?)\\}', 'g');
data.content = data.content.replace(RE, function(x, y) {
num += 1;
footContent += '<div class="footdef"><sup><a id="fn.' + num + '" name="fn.' + num + '" class="footnum" href="#fnr.' + num + '">' + num + '</a></sup> ' + y + '</div>';
return '<sup><a id="fnr.' + num + '" class="footref" href="#fn.' + num + '" name="fnr.' + num + '">' + num + '</a></sup>';
});
if (footContent.length > 0) {
data.content = data.content + '<div id="footnotes"><h3 class="footnotes">' + fnName + '</h3><div id="text-footnotes">' + footContent + '</div></div>';
}
return data;
});
/*
furi.js (former furigana.js): A filter for Hexo to generate 2-language comparison like furigana. Place this file in /scripts/furigana.js.
========================================================================
Author: Yoxem <yoxem.tem98[ A T ]nctu.edu.tw>,kuanyui(azazabc123[at]g~~~m~~~a~~~i~~~l[dot]com)
Date: 20180730
License: WTFPL 1.0
========================================================================
The string in article:
{fr|平安|peace}
Will be converted to: 2 lines.
*/
hexo.extend.filter.register('post', function(data, callback) {
var reRb = new RegExp('\\{fr\\|(.+?)\\|(.+?)\\}', 'g');
data.content = data.content.replace(reRb, '<div style="display:table;float:left;margin-right:0.2em;"><div style="display:table-row;">$1</div><div style="display:table-row;font-size:70%;text-align:center;">$2</div></div>');
// fre: added to the end punctuation of the line. eg. {fr|Eh|e}{frb|?}
var reRb = new RegExp('\\{fre\\|(.+?)\\}', 'g');
data.content = data.content.replace(reRb, '<div style="left:-0.2em;position: relative;">$1</div><div style="clear:left;"></div>');
//callback(null, data);
return data;
});
English
--------
The gist contains the scripts used with Hexo. To install them, you just download them to [Hexo blog folder]/scripts.
Description:
- footnote.js: a footnote generator.
- furi.js: furigana.
- fuby.js: ruby characters. (add phonetic description)
The license(s) for them is/are shown in their source code file.
官話
--------
這個 gist 是收藏我安裝的 Hexo script。置放到 [Hexo 部落格目錄]/scripts 即可安裝。
說明:
- footnote.js:讓 Hexo 能夠使用註腳的功能。
- furi.js:振假名(日語:furigana)。
- ruby.js:旁註標記(加注音)。
授權參考各檔案內容。
/*
ruby.js: A filter for Hexo to generate ruby chracters(ルビ). Place this file in /scripts/ruby.js.
========================================================================
Author: kuanyui(azazabc123[at]g~~~m~~~a~~~i~~~l[dot]com), Yoxem <yoxem.tem98[ A T ]nctu.edu.tw>
Date: 20180730
License: WTFPL 1.0
========================================================================
The string in article:
{rb|機巧少女|machine doll}
Will be converted to:
<ruby><rb>機巧少女</rb><rp>[</rp><rt>machine doll</rt><rp>]</rp></ruby>
*/
hexo.extend.filter.register('post', function(data, callback) {
var reRb = new RegExp('\\{rb\\|(.+?)\\|(.+?)\\}', 'g');
data.content = data.content.replace(reRb, '<ruby><rb>$1</rb><rp>[</rp><rt>$2</rt><rp>]</rp></ruby>');
// callback(null, data);
return data;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment