Skip to content
This repository has been archived by the owner on Jun 4, 2022. It is now read-only.

2.0 pre测试中的一些小问题 #41

Closed
dengcb opened this issue Apr 16, 2018 · 8 comments
Closed

2.0 pre测试中的一些小问题 #41

dengcb opened this issue Apr 16, 2018 · 8 comments
Labels
bug:core Issues about layout, styles, scripts, etc.

Comments

@dengcb
Copy link

dengcb commented Apr 16, 2018

我更新到了2.0 pre,同时使用hexo-multilingual做全站多语言,发现了一些小问题。
包配置如下:

{
  "name": "hexo-site",
  "version": "0.0.0",
  "private": true,
  "hexo": {
    "version": "3.7.0"
  },
  "dependencies": {
    "deepmerge": "^2.1.0",
    "hexo": "^3.7.0",
    "hexo-deployer-git": "^0.3.1",
    "hexo-generator-json-content": "^3.0.1",
    "hexo-generator-multilingual-archive": "^0.2.0",
    "hexo-generator-multilingual-category": "^0.3.2",
    "hexo-generator-multilingual-feed": "^1.2.2",
    "hexo-generator-multilingual-index": "^0.3.1",
    "hexo-generator-tag": "^0.2.0",
    "hexo-multilingual": "^0.6.0",
    "hexo-pagination": "^0.1.0",
    "hexo-renderer-ejs": "^0.3.0",
    "hexo-renderer-marked": "^0.3.0",
    "hexo-renderer-sass": "^0.3.2",
    "hexo-renderer-stylus": "^0.3.1",
    "hexo-server": "^0.2.0",
    "lodash": "^4.17.5",
    "underscore": "^1.8.3"
  }
}

hexo-multilingual系列在minos1.0里很好地完成了全站双语化,但是在2.0里:

  1. 缺失categories、tags、about三个页面的模板,所以出问题了
  2. archives没有生成双语版,之前1.0很完美的双语
  3. 有一部分界面语言还没有中文翻译

参见:https://dengcb.com
期待完善~

@ppoffice
Copy link
Owner

感谢建议,我会逐步更新这些功能

@ppoffice ppoffice added the bug:general Issues with this theme in general. label Apr 16, 2018
@dengcb
Copy link
Author

dengcb commented Apr 17, 2018

我更新了最新dev的代码,惊喜的发现全站多语言基本上实现了。

首先,可以卸载hexo-multilingual的各种generator了,因为最新代码基本上实现了对应功能。
但是,hexo-multilingual这个核心包还是不能卸载,因为它基于

lang: en
label: hello-world

这两个标签,把混在一起的多语言文章给区分开来,在文章详情页上一篇下一篇就不会出现语言混搭。我尝试卸载后,发现多种语言文章混在一起了,如果解决了这个,就可以卸载hexo-multilingual了。

其他,发现的一些小问题,比如:

  1. about还没有多语言,可以引申为,所有page页是否可以用lang和label两个标签来区分多语言。
  2. 文章详情页的分类和书签链接,默认语言还是带en,无效。其实,我在config里用两个map完美实现双语分类和书签的切换。
category_map:
  无他: nothing
tag_map:
  随笔: anything
  1. Insight search现在貌似只能搜英文了,之前中英混搜,我觉得最好能分开,实在不行混在一起也行。
  2. _config.<lang>.yml 里能对title、subtitle、description、date_format进行多语言定义吗?
  3. disqus.ejs里添加this.language = '<%= theme.lang %>';实现多语言化。
  4. 想添加一个语言跳转链接,我把footer改了,因为我只有2种语言的需求,所以简单暴力写了个死的切换函数,暂时实现了需求。如果你能写一个通用版切换器就完美了!

我想,双语应该是大部分人的需求,en默认,再加一个自己的母语。期待下一次更新。

@ppoffice
Copy link
Owner

ppoffice commented Apr 17, 2018

@dengcb
首先需要在根目录下_config.yml设置多语言

language:
- en
- zh-cn

可以使用如下目录结构,无需设置lang

_post/
    my_post.md
    zh-cn/
        my_post.md
about/
    index.md
zh-cn/
    about/
        index.md

subtitle, description, date_format未在本主题中使用。
另外,更新之后无需再使用hexo-multilingual和hexo-generator-json-content.

@dengcb
Copy link
Author

dengcb commented Apr 18, 2018

我在测试的过程中,感觉到约定大于配置,会省很多事,否则会出现各种问题。
我把根配置里稀奇古怪的地方都改成默认的了,然后按照你给的目录结构进行了重新布局。

_post/
  hello-world.md
  zh-cn/
    hello_world.md
about/
  index.md
zh-cn/
  about/
    index.md

另外,把包也精简了

{
  "name": "dengcb.github.io",
  "version": "1.0.0",
  "private": true,
  "hexo": {
    "version": "3.7.1"
  },
  "dependencies": {
    "hexo": "^3.7.1",
    "hexo-deployer-git": "^0.3.1",
    "hexo-generator-archive": "^0.1.5",
    "hexo-generator-category": "^0.1.3",
    "hexo-generator-index": "^0.2.1",
    "hexo-generator-tag": "^0.2.0",
    "hexo-pagination": "^0.1.0",
    "hexo-renderer-ejs": "^0.3.0",
    "hexo-renderer-marked": "^0.3.0",
    "hexo-renderer-sass": "^0.3.2",
    "hexo-renderer-stylus": "^0.3.1",
    "hexo-server": "^0.2.0"
  }
}

之前绝大部分问题都消失了,功能也很完美。

当然,还有些bug,如下:

  1. 文章详情里分类和书签,在英文下,会有错链:/en/tags/anything, /en/categories/nothing
  2. 文章发布时间和阅读时间,中文下没有翻译,还是“8 Days Ago”
  3. 菜单Category和Tag点击进去,title漏了,只有站点名称
  4. footer里,切换器会被footer_links配置影响,应该这样
<% } %>
<%- partial('common/languages') %>
  1. 如果根配置这样写permalink: :category/:title/,文章中文链接就会变成这样
    /nothing/zh/hello-world/

其他我觉得很好,准备写一篇文章帮小白入门。

@ppoffice
Copy link
Owner

ppoffice commented Apr 18, 2018

  1. 与时间有关的翻译是由moment.js处理的,它使用的是ll-cc格式的语言代码,所以zh-cn可以翻译成中文,但是zh就不行。各个第三方库使用的语言代码格式不一,目前我在Disqus, Facebook comment pluginmoment.js中把用户配置的语言代码转尽可能地转换成了它们需要的语言格式。关于语言格式的话请查阅ISO639RFC5646

  2. 目前如果在一个站点中使用多语言,并且对于同一个post需要支持多个语言版本的话,必须保证post的path或者permalink以语言名开头,如zh-cn/example.md。这种情况下,设置permalink: :slug/...是最好的。而且因为post放到了zh-cn目录中,所以post的slug和title都是以zh-cn开头的。所以这个是Hexo对于permalink的规定。设置为permalink: :category/:title/的话会导致切换语言的时候文章路径错误。

@dengcb
Copy link
Author

dengcb commented Apr 19, 2018

首先,非常感谢能为我兼容 zh≈zh-cn 这种不严谨的诡异要求,我就是个对称控。

其次,我再也测不出bug了,除了修改了一点点代码,把index.html给匿了(还是强迫症)。

我在blog上也写了一篇 文章,讲述整个过程。

关闭此帖!

@dengcb dengcb closed this as completed Apr 19, 2018
@dengcb
Copy link
Author

dengcb commented Apr 19, 2018

最后,想起一点,不算bug,是不是head里少了一些meta,所以没有弹出谷歌翻译网页的东东,也就是没有强迫网页是某种语言属性。其实这样挺好,每次弹谷歌翻译也很烦人。

@dengcb
Copy link
Author

dengcb commented Apr 23, 2018

发现一些缺陷:
在多语言站点里,应该在head里添加alternate url,如:

<link href="https://dengcb.com/hello-world/" rel="alternate" hreflang="en" />
<link href="https://dengcb.com/zh/hello-world/" rel="alternate" hreflang="zh" />

这样,对搜索引擎更友好,seo更好

@ppoffice ppoffice added bug:core Issues about layout, styles, scripts, etc. and removed bug:general Issues with this theme in general. labels Jun 20, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug:core Issues about layout, styles, scripts, etc.
Projects
None yet
Development

No branches or pull requests

2 participants