From 4c10b83e1495ea6e342f968b2ca0f7ea353537c6 Mon Sep 17 00:00:00 2001 From: xaoxuu Date: Tue, 2 Jan 2024 20:19:49 +0800 Subject: [PATCH] [opt] links: friends & sites --- scripts/events/index.js | 1 + scripts/events/lib/links.js | 17 +++++++++++++++++ scripts/tags/lib/friends.js | 4 ++-- scripts/tags/lib/sites.js | 6 +++--- source/js/plugins/friends.js | 2 +- source/js/plugins/sites.js | 4 ++-- 6 files changed, 26 insertions(+), 8 deletions(-) create mode 100644 scripts/events/lib/links.js diff --git a/scripts/events/index.js b/scripts/events/index.js index 176282f..8c315ce 100644 --- a/scripts/events/index.js +++ b/scripts/events/index.js @@ -5,6 +5,7 @@ hexo.on('generateBefore', () => { // Merge config. require('./lib/config')(hexo); + require('./lib/links')(hexo); require('./lib/doc_tree')(hexo); require('./lib/utils')(hexo); }); diff --git a/scripts/events/lib/links.js b/scripts/events/lib/links.js new file mode 100644 index 0000000..59765f1 --- /dev/null +++ b/scripts/events/lib/links.js @@ -0,0 +1,17 @@ +/** + * doc_tree.js v2 | https://github.com/xaoxuu/hexo-theme-stellar/ + */ + +'use strict'; + +module.exports = ctx => { + var allLinks = {} + const data = ctx.locals.get('data') + for (let key of Object.keys(data)) { + if (key.startsWith('links/')) { + let newKey = key.replace('links/', '') + allLinks[newKey] = data[key] + } + } + ctx.theme.config.links = allLinks +} \ No newline at end of file diff --git a/scripts/tags/lib/friends.js b/scripts/tags/lib/friends.js index 636c54b..671e142 100644 --- a/scripts/tags/lib/friends.js +++ b/scripts/tags/lib/friends.js @@ -9,7 +9,7 @@ module.exports = ctx => function(args) { args = ctx.args.map(args, ['repo', 'api'], ['group']) - var links = ctx.locals.get('data').links + var links = ctx.theme.config.links if (links == undefined) { links = {} } @@ -32,7 +32,7 @@ module.exports = ctx => function(args) { if (item.url && item.title) { var cell = '
' cell += '' - cell += '' + cell += '' cell += '
' + item.title + '
' cell += '
' return cell diff --git a/scripts/tags/lib/sites.js b/scripts/tags/lib/sites.js index e0a69b0..4f20f98 100644 --- a/scripts/tags/lib/sites.js +++ b/scripts/tags/lib/sites.js @@ -9,7 +9,7 @@ module.exports = ctx => function(args) { args = ctx.args.map(args, ['repo', 'api'], ['group']) - var links = ctx.locals.get('data').links + var links = ctx.theme.config.links if (links == undefined) { links = {} } @@ -32,9 +32,9 @@ module.exports = ctx => function(args) { if (item.url && item.title) { var cell = '
' cell += '' - cell += '' + cell += '' cell += '
' - cell += '' + cell += '' cell += '' + item.title + '' cell += '' + (item.description || item.url) + '' cell += '
' diff --git a/source/js/plugins/friends.js b/source/js/plugins/friends.js index bb81d91..ef46019 100644 --- a/source/js/plugins/friends.js +++ b/source/js/plugins/friends.js @@ -52,7 +52,7 @@ const friendsjs = { var user = '
'; diff --git a/source/js/plugins/sites.js b/source/js/plugins/sites.js index d76f45d..d1e22f2 100644 --- a/source/js/plugins/sites.js +++ b/source/js/plugins/sites.js @@ -51,9 +51,9 @@ const sitesjs = { arr.forEach((item, i) => { var cell = '