Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug Fix: about footer.swig #1541

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ custom_file_path:
#mixin: source/_data/mixins.styl
#style: source/_data/styles.styl

# i18n Path
# Correct handling of i18n path
i18n:
# Mode
# 1: All language independent directory under <Public/>.
# 2: Default language(hexo.config.language[0]) is under <Public/>
mode: 1
#Type : [posts, archives, categories, tags, about, ...]
type:


# ---------------------------------------------------------------
# Site Information Settings
Expand Down Expand Up @@ -65,6 +75,7 @@ footer:

# If not defined, `author` from Hexo `_config.yml` will be used.
copyright:
copyright_url:

# Powered by Hexo & NexT
powered: true
Expand All @@ -73,6 +84,8 @@ footer:
beian:
enable: false
icp:
# ICP region. See: http://www.miit.gov.cn/n1146285/n1146352/n3054355/n3057709/n3057722/c6797266/content.html
icp_region: gd
# The digit in the num of gongan beian.
gongan_id:
# The full num of gongan beian.
Expand Down
24 changes: 21 additions & 3 deletions layout/_partials/footer.swig
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
{%- if theme.footer.beian.enable %}
<div class="beian">
{{- next_url('http://www.beian.miit.gov.cn', theme.footer.beian.icp + ' ') }}
<span> ICP: </span>
{%- if theme.footer.beian.icp_region and theme.footer.beian.icp_region != '' %}
{%- set icp_region = theme.footer.beian.icp_region %}
{%- else %}
{%- set icp_region = 'bj' %}
{%- endif %}
{{- next_url('http://' + icp_region + '.beian.miit.gov.cn', theme.footer.beian.icp + ' ') }}
{%- if theme.footer.beian.gongan_icon_url %}
<img src="{{ url_for(theme.footer.beian.gongan_icon_url) }}" style="display: inline-block;">
&nbsp; <img src="{{ url_for(theme.footer.beian.gongan_icon_url) }}" style="display: inline-block;">
{%- endif %}
{%- if theme.footer.beian.gongan_id and theme.footer.beian.gongan_num %}
{{- next_url('http://www.beian.gov.cn/portal/registerSystemInfo?recordcode=' + theme.footer.beian.gongan_id, theme.footer.beian.gongan_num + ' ') }}
Expand All @@ -12,12 +18,24 @@

<div class="copyright">
{% set copyright_year = date(null, 'YYYY') %}
<span> Copyright </span>
&copy; {% if theme.footer.since and theme.footer.since != copyright_year %}{{ theme.footer.since }} – {% endif %}
<span itemprop="copyrightYear">{{ copyright_year }}</span>
<span class="with-love">
<i class="{{ theme.footer.icon.name }}"></i>
</span>
<span class="author" itemprop="copyrightHolder">{{ theme.footer.copyright or author }}</span>
{%- if theme.footer.copyright %}
{%- set copyright_author = theme.footer.copyright %}
{%- else %}
{%- set copyright_author = author %}
{%- endif %}
<span class="author" itemprop="copyrightHolder">
{%- if theme.footer.copyright_url %}
{{- next_url(theme.footer.copyright_url, copyright_author , {target: '_blank'}) }}
{%- else %}
{{ copyright_author }}
{%- endif %}
</span>

{%- if config.symbols_count_time.total_symbols %}
<span class="post-meta-divider">|</span>
Expand Down
29 changes: 28 additions & 1 deletion layout/_partials/header/menu-item.swig
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,39 @@
{%- set itemURL = value.split('||')[0] | trim %}
{%- if not itemURL.startsWith('http') %}
{%- set itemURL = itemURL | replace('//', '/') %}
{%- set RPStr = itemURL | replace('/', '') %}
{%- set i18nType = theme.i18n.type %}
{%- set i18nMode = theme.i18n.mode %}

{%- if i18nType and i18nType.length > 1 %}
{%- if i18nType[0].length < 1 %}
{%- set i18nType = [i18nType] %}
{%- endif %}
{%- endif %}
{%- if languages and languages.length > 1 %}
{%- if languages[0].length < 1 %}
{%- set languages = [languages] %}
{%- endif %}
{%- set languageStr = '/' + languages[0] %}
{% else %}
{%- set languageStr = '' %}
{%- endif %}

{%- if i18nType and i18nType.length > 1 %}
{%- for i in i18nType %}
{%- if RPStr | lower == i | lower %}
{%- if i18nMode == 1 %}
{%- set itemURL = languageStr + itemURL %}
{%- endif %}
{%- endif %}
{%- endfor %}
{%- endif %}
{%- endif %}
<li class="menu-item menu-item-{{ itemName | replace(' ', '-') }}">

{%- set menuIcon = '' %}
{%- if theme.menu_settings.icons %}
{%- set menuIcon = '<i class="' + value.split('||')[1] | trim + ' fa-fw"></i>' %}
{%- set menuIcon = '<i class="fa fa-fw fa-' + value.split('||')[1] | trim + '"></i>' %}
{%- endif %}
{%- set menuText = __('menu.' + name) | replace('menu.', '') %}

Expand Down
66 changes: 51 additions & 15 deletions layout/_partials/sidebar/site-overview.swig
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,59 @@
</div>

{%- if theme.site_state %}
{%- if theme.menu.archives %}
{%- set archivesURL = theme.menu.archives.split('||')[0] | trim %}
{% else %}
{%- set archivesURL = config.archive_dir %}
{%- endif %}
{%- if theme.menu.categories %}
{%- set categoriesURL = theme.menu.categories.split('||')[0] | trim %}
{% else %}
{%- set categoriesURL = config.category_dir %}
{%- endif %}
{%- if theme.menu.tags %}
{%- set tagsURL = theme.menu.tags.split('||')[0] | trim %}
{% else %}
{%- set tagsURL = config.tag_dir %}
{%- endif %}

{%- set i18nType = theme.i18n.type %}
{%- set i18nMode = theme.i18n.mode %}
{%- if i18nType and i18nType.length > 1 %}
{%- if i18nType[0].length < 1 %}
{%- set i18nType = [i18nType] %}
{%- endif %}
{%- endif %}
{%- if languages and languages.length > 1 %}
{%- if languages[0].length < 1 %}
{%- set languages = [languages] %}
{%- endif %}
{%- set languageStr = '/' + languages[0] + '/' %}
{% else %}
{%- set languageStr = '' %}
{%- endif %}

{%- if i18nType and i18nType.length > 1 %}
{%- for i in i18nType %}
{%- if i18nMode == 1 %}
{%- if archivesURL | lower == i | lower %}
{%- set archivesURL = languageStr + archivesURL + '/' %}
{%- endif %}
{%- if categoriesURL | lower == i | lower %}
{%- set categoriesURL = languageStr + categoriesURL + '/' %}
{%- endif %}
{%- if tagsURL | lower == i | lower %}
{%- set tagsURL = languageStr + tagsURL + '/' %}
{%- endif %}
{%- endif %}
{%- endfor %}
{%- endif %}

<div class="site-state-wrap motion-element">
<nav class="site-state">
{%- if config.archive_dir != '/' and site.posts.length > 0 %}
<div class="site-state-item site-state-posts">
{%- if theme.menu.archives %}
<a href="{{ url_for(theme.menu.archives.split('||')[0] | trim) }}">
{% else %}
<a href="{{ url_for(config.archive_dir) }}">
{%- endif %}
<a href="{{ url_for(archivesURL) }}">
<span class="site-state-item-count">{{ site.posts.length }}</span>
<span class="site-state-item-name">{{ __('state.posts') }}</span>
</a>
Expand All @@ -28,11 +72,7 @@
{%- set hasCategoriesPage = categoriesPageQuery.length > 0 %}
<div class="site-state-item site-state-categories">
{%- if hasCategoriesPage %}
{%- if theme.menu.categories %}
<a href="{{ url_for(theme.menu.categories.split('||')[0] | trim) }}">
{% else %}
<a href="{{ url_for(config.category_dir) + '/' }}">
{%- endif %}
<a href="{{ url_for(categoriesURL) }}">
{%- endif %}
<span class="site-state-item-count">{{ site.categories.length }}</span>
<span class="site-state-item-name">{{ __('state.categories') }}</span>
Expand All @@ -45,11 +85,7 @@
{%- set hasTagsPage = tagsPageQuery.length > 0 %}
<div class="site-state-item site-state-tags">
{%- if hasTagsPage %}
{%- if theme.menu.tags %}
<a href="{{ url_for(theme.menu.tags.split('||')[0] | trim) }}">
{% else %}
<a href="{{ url_for(config.tag_dir) + '/' }}">
{%- endif %}
<a href="{{ url_for(tagsURL) }}">
{%- endif %}
<span class="site-state-item-count">{{ site.tags.length }}</span>
<span class="site-state-item-name">{{ __('state.tags') }}</span>
Expand Down
63 changes: 60 additions & 3 deletions scripts/helpers/engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,66 @@ hexo.extend.helper.register('canonical', function() {
* Get page path given a certain language tag
*/
hexo.extend.helper.register('i18n_path', function(language) {
const { path, lang } = this.page;
const base = path.startsWith(lang) ? path.slice(lang.length + 1) : path;
return this.url_for(`${this.languages.indexOf(language) === 0 ? '' : '/' + language}/${base}`);
const { path, lang } = this.page;
let base = path.startsWith(lang) ? path.slice(lang.length + 1) : path;
const trailing_index = hexo.config.pretty_urls.trailing_index;
const trailing_html = hexo.config.pretty_urls.trailing_html;
const theme = hexo.theme.config;
let i18nType = theme.i18n.type;
let i18nMode = theme.i18n.mode;

// Debug
// console.log('base: ' + base);

// Init options
if (i18nType && i18nType.length) {
if (!Array.isArray(i18nType)) {
i18nType = [i18nType];
}
}
if (!i18nMode || i18nMode.length == 0) {
i18nMode = 1;
}

// 404/aa/index.html => ["404","aa","index.html"]
let RPStr = base.split("/")[0];

if (trailing_index && trailing_index === false) {
// 404/aa/index.html => 404/aa/
base = base.replace(/index.html$/gi, '');
}
if (trailing_html && trailing_html === false) {
// 404/aa/index.html => 404/aa/index
base = base.replace(/html$/gi, '');
}

let i18nPath = this.url_for('/' + base);
if (i18nType && i18nType.length) {
for (const i of i18nType) {
if (RPStr.toLowerCase() === i.toLowerCase()) {
if (i18nMode == 1) {
i18nPath = this.url_for('/' + language + '/' + base);
}
if (i18nMode == 2) {
// this.languages.indexOf(language) === 0
// The indexOf() method can return the location where the specified string value first appears in the string.
// languages: ["en","zh-CN"] language: en => 0
i18nPath = this.url_for(`${this.languages.indexOf(language) === 0 ? '' : '/' + language}/${base}`);
}
}
}
}

// Debug
// console.log('base2: ' + base);
// console.log('RPStr: ' + RPStr);
// console.log('language: ' + language);
// console.log('i18nMode: ' + i18nMode);
// console.log('i18nPath: ' + i18nPath);
// console.log('languages: ' + JSON.stringify(this.languages));
// console.log(' ');

return i18nPath;
});

/**
Expand Down
2 changes: 1 addition & 1 deletion scripts/tags/mermaid.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
'use strict';

function mermaid(args, content) {
return `<pre class="mermaid" style="text-align: center;">
return `<pre class="mermaid" style="text-align: center;background: currentColor;">
${args.join(' ')}
${content}
</pre>`;
Expand Down