From 900e3bec264d9bb7e9d50d465142d19362e88d17 Mon Sep 17 00:00:00 2001 From: eddy1937 Date: Thu, 25 Apr 2024 23:26:49 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E7=94=A8=20npm=20=E8=BC=89=E5=85=A5?= =?UTF-8?q?=20hexo-generator-i18n-404?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 3 +- scripts/generator-i18n-404.js | 53 ----------------------------------- 2 files changed, 2 insertions(+), 54 deletions(-) delete mode 100644 scripts/generator-i18n-404.js diff --git a/package.json b/package.json index 2e54376..eb474ee 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,7 @@ "hexo-renderer-marked": "6.0.0", "hexo-renderer-stylus": "3.0.0", "hexo-server": "3.0.0", - "hexo-theme-landscape": "1.0.0" + "hexo-theme-landscape": "1.0.0", + "hexo-generator-i18n-404": "git+https://github.com/eddy1937/hexo-generator-i18n-404.git" } } diff --git a/scripts/generator-i18n-404.js b/scripts/generator-i18n-404.js deleted file mode 100644 index 1742f9e..0000000 --- a/scripts/generator-i18n-404.js +++ /dev/null @@ -1,53 +0,0 @@ -const { title } = require("hexo/dist/hexo/default_config"); - -const postPermalink = (post) => hexo.execFilterSync('post_permalink', post, {context: hexo}); - -const postPermalinkBylang = (post, lang) => { - const cacheLang = post.lang; - post.lang = lang; - const path = postPermalink(post); - post.lang = cacheLang; - return path; -}; - -const i18n_404 = hexo.config.i18n_404; - -const defaultInfo = { - title: i18n_404?.default?.title ?? 'Sorry! Post Not Found', - description: i18n_404?.default?.description -} - -const generatorNotFoundPost = (path, lang) => { - return { - path: path, - data: { - title: i18n_404[lang]?.title ?? defaultInfo.title, - lang: lang, - permalink: path, - description: i18n_404[lang]?.description ?? defaultInfo.description, - copyright: false, - // content: '' - }, - layout: ['post'], - }; -} - -hexo.extend.generator.register('i18n-404', function(locals){ - const config = this.config; - if(!config.language) { - return []; - } - const languages = new Set(config.language.filter(lang => lang !== 'default')); - return Array.from(locals.posts.reduce((map, post) => { - if (languages.has(post.lang) && !map.delete(postPermalink(post))) { - languages.forEach((lang) => { - if (lang === post.lang) { - return; - }; - const _path = postPermalinkBylang(post, lang); - map.set(_path, generatorNotFoundPost(_path, lang)); - }); - } - return map; - }, new Map()).values()); -}); \ No newline at end of file