npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

hexo-generator-i18n-post

v1.0.0

Published

A plugin to generate i18n posts based on the identifier in front matter

Downloads

7

Readme

Hexo i18n Post Generator

This plugin currently tested on Hexo 4.3.1. It may not work on other versions. This plugin will add the language to the path of the post. For example, if you have a post named hello-world, and you have two languages, en(default) and zh-CN, then the path of the post will be like 2022/01/01/hello-world/ and zh-CN/2022/01/01/hello-world/. It also support group by post, which means the path will be like 2022/01/01/hello-world/ and 2022/01/01/hello-world/zh-CN/.

Installation

npm install hexo-generator-i18n-post --save

Usage

Add configuration in your _config.yml:

# i18n post generator config
i18n_post_generator:
  # `group_by` available value is `post`, `lang`, default is `post`
  group_by: post
  # identifier_field is used to identify the unique post, default is `slug`, however, a custom field is recommended
  identifier_field: slug
  • group_by is used to group the posts, if you set it to post, then the posts will be grouped by post, if you set it to lang, then the posts will be grouped by lang. e.g. if group_by is post, the path will be like: :year/:month/:day/:title/:lang/, otherwise group_by is lang, the path will be like: :lang/:year/:month/:day/:title/. However, if you set permalink pattern in your hexo root config to :year/:month/:day/:title/, then there would be potential path issue. For example, if you have a post named hello-world, and you have two languages, en and zh-CN, then the path of the post will be like 2022/01/01/hello-world/ and en/2022/01/01/hello-world/, but if the date of these two posts are different, then the path will be like 2022/01/01/hello-world/ and en/2022/01/02/hello-world/, which will not work if you use the default language switcher by Hexo. So, if you want to use this plugin, you'd better set permalink pattern to :title or use a custom switcher.
  • identifier_field is used to identify the unique post, default is slug, however, a custom field is recommended since slug is not unique in some cases, e.g. source/_data/2019-01-01-hello-world.md and source/_data/en/2019-01-01-hello-world.md will have different slug but we want them to be the same post. If you still want to use slug, it will help you to trim the en/ by split the slug with /, but it doesnot always work for all general cases.

TODO

  • [ ] Add hexo cli plugin to generate i18n post

Misc

To set the header(menu-item) link for each language, you can change the template for url in your theme, for example, in NexT theme, you can change the template in themes/next/layout/_partials/header/menu-item.njk:

{# ... #}
{% if page.lang == languages[0] %}
    {%- set itemURL = node.path %}
{% else %}
    {%- set itemURL = page.lang + '/' + node.path %}
{% endif %}
{{- next_url(itemURL, menuIcon + menuText + menuBadge, {rel: 'section'}) -}}
{# ... #}

where languages[0] is the default language, and page.lang is the language of the current page.