limour-dev 5 months ago
parent
commit
58f9158f5e

+ 2 - 1
.gitignore

@@ -2,8 +2,9 @@
 Thumbs.db
 db.json
 *.log
-node_modules/
+node_modules/*
 !node_modules/hexo-theme-fluid/scripts/generators/local-search.js
+!node_modules/hexo-theme-fluid/layout/_partials/head.ejs
 public/
 .deploy*/
 _multiconfig.yml

+ 50 - 0
node_modules/hexo-theme-fluid/layout/_partials/head.ejs

@@ -0,0 +1,50 @@
+<%
+var separator = theme.title_join_string || theme.tab_title_separator
+var title = page.title ? [page.title, config.title].join(separator) : config.title
+var keywords = page.keywords || config.keywords
+if (keywords instanceof Array) {
+  keywords = keywords.join(',')
+}
+var description = page.description || page.excerpt || (is_post() && page.content) || config.description
+if (description) {
+  description = strip_html(description).substring(0, 200).trim().replace(/\n/g, ' ')
+}
+var ogImage = page.og_img || page.index_img
+var ogConfig = Object.assign({ image: ogImage && url_for(ogImage) }, theme.open_graph)
+%>
+
+<head>
+  <meta charset="UTF-8">
+  <link rel="apple-touch-icon" sizes="76x76" href="<%= url_for(theme.apple_touch_icon) %>">
+  <link rel="icon" href="<%= url_for(theme.favicon) %>">
+  <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0, shrink-to-fit=no">
+  <meta http-equiv="x-ua-compatible" content="ie=edge">
+  <% if (theme.force_https) { %>
+    <meta http-equiv="Content-Security-Policy" content="upgrade-insecure-requests">
+  <% } %>
+  <meta name="theme-color" content="<%= theme.color.navbar_bg_color %>">
+  <meta name="author" content="<%= page.author || config.author %>">
+  <meta name="keywords" content="<%= keywords %>">
+  <% if (theme.open_graph.enable) { %>
+    <%- open_graph(ogConfig) %>
+  <% } else { %>
+    <meta name="description" content="<%= description %>">
+  <% } %>
+  <% if ((theme.post.meta.views.enable && theme.post.meta.views.source === 'busuanzi')
+    || (theme.footer.statistics.enable && theme.footer.statistics.source === 'busuanzi')) { %>
+    <meta name="referrer" content="no-referrer-when-downgrade">
+  <% } %>
+  <% if (theme.custom_head) { %>
+    <%- theme.custom_head %>
+  <% } %>
+  <title><%= title %></title>
+
+  <%- partial('_partials/css.ejs') %>
+  <%- export_config() %>
+  <%- js_ex(theme.static_prefix.internal_js, 'utils.js') %>
+  <%- js_ex(theme.static_prefix.internal_js, 'color-schema.js') %>
+  <%- partial('_partials/plugins/analytics.ejs') %>
+
+  <%- inject_point('head') %>
+  <%- autoCanonical(config, page) %>
+</head>

+ 21 - 21
package-lock.json

@@ -9,7 +9,7 @@
       "version": "0.0.0",
       "dependencies": {
         "@traptitech/markdown-it-katex": "^3.6.0",
-        "hexo": "^7.0.0",
+        "hexo": "^7.1.1",
         "hexo-deployer-git": "^4.0.0",
         "hexo-filter-links": "^1.0.7",
         "hexo-generator-archive": "^2.0.0",
@@ -20,9 +20,9 @@
         "hexo-generator-sitemap": "^3.0.1",
         "hexo-generator-tag": "^2.0.0",
         "hexo-renderer-ejs": "^2.0.0",
-        "hexo-renderer-markdown-it": "^7.1.0",
+        "hexo-renderer-markdown-it": "^7.1.1",
         "hexo-renderer-pug": "^3.0.0",
-        "hexo-renderer-stylus": "^3.0.0",
+        "hexo-renderer-stylus": "^3.0.1",
         "hexo-server": "^3.0.0",
         "hexo-theme-fluid": "^1.9.7"
       }
@@ -1324,9 +1324,9 @@
       }
     },
     "node_modules/hexo": {
-      "version": "7.0.0",
-      "resolved": "https://registry.npmmirror.com/hexo/-/hexo-7.0.0.tgz",
-      "integrity": "sha512-3iRSYReDcYd+bdCrDYS53aFjR717M+eSwKVXdM1tF2QETi8urcwDdDDoD7Nm2E0trqN4oeoHJ7FoXbn2UsZxqw==",
+      "version": "7.1.1",
+      "resolved": "https://registry.npmmirror.com/hexo/-/hexo-7.1.1.tgz",
+      "integrity": "sha512-u6aJXG1npYkZJLl7QEOeTdm9hOwxfsLmFp4qAQVF0OAuNaikrKORjgNsjPmrWwI/tIObwjVJnEUJnV7S+NnUlw==",
       "dependencies": {
         "abbrev": "^2.0.0",
         "archy": "^1.0.0",
@@ -2556,9 +2556,9 @@
       }
     },
     "node_modules/hexo-renderer-markdown-it": {
-      "version": "7.1.0",
-      "resolved": "https://registry.npmmirror.com/hexo-renderer-markdown-it/-/hexo-renderer-markdown-it-7.1.0.tgz",
-      "integrity": "sha512-CQK7/kvhWbpKzXOSTpSuANVKgOZjPzxkPna4IQ6xMnRqsNpVXNSzpn5Ke1QEVH2x6FJB1/Vf7B40sJVxQKagaw==",
+      "version": "7.1.1",
+      "resolved": "https://registry.npmmirror.com/hexo-renderer-markdown-it/-/hexo-renderer-markdown-it-7.1.1.tgz",
+      "integrity": "sha512-BxI2j2f/l7lOgb7DiT1M4GcP/QhR8/rjMlYx4MEPog/9NTpYhbaspiVsw3tGXOsZVmu+cVgBYoeyIQsFYvv3rw==",
       "dependencies": {
         "hexo-util": "^3.0.1",
         "markdown-it": "^13.0.1",
@@ -2590,12 +2590,12 @@
       }
     },
     "node_modules/hexo-renderer-stylus": {
-      "version": "3.0.0",
-      "resolved": "https://registry.npmmirror.com/hexo-renderer-stylus/-/hexo-renderer-stylus-3.0.0.tgz",
-      "integrity": "sha512-wgKOcjUzq1i4Y70luoyYDbh91QeQcDzJO+v1598LgY+IdREFAm+vy1MWtl/TZsVXyPaEtsULNi3Vi22hdsPUSA==",
+      "version": "3.0.1",
+      "resolved": "https://registry.npmmirror.com/hexo-renderer-stylus/-/hexo-renderer-stylus-3.0.1.tgz",
+      "integrity": "sha512-cFm8ZwShBBeFcQwOXc8EK7lIZnSYVD6OJykdL4GBw99hxc4eD5Hlsi32nRzE8sgKv00jhX1s9Da3GVVFMPAVQg==",
       "dependencies": {
         "nib": "^1.2.0",
-        "stylus": "^0.59.0"
+        "stylus": "^0.62.0"
       },
       "engines": {
         "node": ">=14"
@@ -4175,9 +4175,9 @@
       }
     },
     "node_modules/sax": {
-      "version": "1.2.4",
-      "resolved": "https://registry.npmmirror.com/sax/-/sax-1.2.4.tgz",
-      "integrity": "sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw=="
+      "version": "1.3.0",
+      "resolved": "https://registry.npmmirror.com/sax/-/sax-1.3.0.tgz",
+      "integrity": "sha512-0s+oAmw9zLl1V1cS9BtZN7JAd0cW5e0QH4W3LWEK6a4LaLEA2OTpGYWDY+6XasBLtz6wkm3u1xRw95mRuJ59WA=="
     },
     "node_modules/send": {
       "version": "0.18.0",
@@ -4525,14 +4525,14 @@
       "integrity": "sha512-vZTvmFP0IYu/zn8MXV6PrLb6VKbd9WGSEnlm4D5RNXS/+zYYlHrSfJgoBw1w56D6RJCr515er3BittRGQqihLA=="
     },
     "node_modules/stylus": {
-      "version": "0.59.0",
-      "resolved": "https://registry.npmmirror.com/stylus/-/stylus-0.59.0.tgz",
-      "integrity": "sha512-lQ9w/XIOH5ZHVNuNbWW8D822r+/wBSO/d6XvtyHLF7LW4KaCIDeVbvn5DF8fGCJAUCwVhVi/h6J0NUcnylUEjg==",
+      "version": "0.62.0",
+      "resolved": "https://registry.npmmirror.com/stylus/-/stylus-0.62.0.tgz",
+      "integrity": "sha512-v3YCf31atbwJQIMtPNX8hcQ+okD4NQaTuKGUWfII8eaqn+3otrbttGL1zSMZAAtiPsBztQnujVBugg/cXFUpyg==",
       "dependencies": {
-        "@adobe/css-tools": "^4.0.1",
+        "@adobe/css-tools": "~4.3.1",
         "debug": "^4.3.2",
         "glob": "^7.1.6",
-        "sax": "~1.2.4",
+        "sax": "~1.3.0",
         "source-map": "^0.7.3"
       },
       "bin": {

+ 1 - 1
package.json

@@ -9,7 +9,7 @@
     "server": "hexo server"
   },
   "hexo": {
-    "version": "7.0.0"
+    "version": "7.1.1"
   },
   "dependencies": {
     "@traptitech/markdown-it-katex": "^3.6.0",

+ 10 - 1
scripts/custom.js

@@ -8,4 +8,13 @@ hexo.extend.injector.register('body_end', `
 // shynet 统计
 hexo.extend.injector.register('head_begin', `
 <script defer src="https://api.limour.top/vue/0d2f95c1-755d-436b-adf8-eee12a80ed32/script.js"></script>
-`);
+`);
+
+// 首选网页 canonical
+hexo.extend.helper.register('autoCanonical', function (config, page) {
+  var base_url = config.url;
+  if (config.url.charAt(config.url.length - 1) !== '/') base_url += '/';
+  base_url += page.canonical_path
+
+  return '<link rel="canonical" href="' + base_url.replace('/index.html', '/').replace(/\.html$/g, '') + '"/>';
+});

+ 18 - 0
source/_posts/2023-08-30-【记录】在-GitHub-上-搭建-Hexo.md

@@ -144,4 +144,22 @@ git fetch --depth=1 -f && git reset --hard origin/gh-pages
       ? base.replace(/\/+$/, '') + '/' + relative.replace(/^\/+/, '')
       : base;
   });
+```
+## 附加 首选网页
++ 编辑 `scripts/custom.js`, 内容如下
+```js
+// 首选网页 canonical
+hexo.extend.helper.register('autoCanonical', function (config, page) {
+  var base_url = config.url;
+  if (config.url.charAt(config.url.length - 1) !== '/') base_url += '/';
+  base_url += page.canonical_path
+
+  return '<link rel="canonical" href="' + base_url.replace('/index.html', '/').replace(/\.html$/g, '') + '"/>';
+});
+```
++ 编辑 `node_modules/hexo-theme-fluid/layout/_partials/head.ejs`, 内容如下
+```js
+// ....
+<%- autoCanonical(config, page) %>
+</head>
 ```