Skip to content

Commit

Permalink
"实现排除页面路径功能以忽略特定页面的链接处理"
Browse files Browse the repository at this point in the history
  • Loading branch information
xyhcode committed Aug 15, 2024
1 parent 44ab6cb commit 808cd3f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ hexo_safego:
- '#article-container'
domain_whitelist: # 域名白名单列表,包含白名单中的域名的链接将被忽略
- 'qyliu.top'
exclude_pages:
- 'fcircle/index.html'
apply_pages: # 生效页面路径列表,只有在这些页面上才会对链接进行处理
- '/posts/'
avatar: /info/avatar.ico # 头像图片链接
Expand Down Expand Up @@ -140,4 +142,4 @@ hexo_safego:

### 问题反馈

如果有任何问题,请提 issue 或者联系作者邮箱 01@liushen.fun,或者在网站中进行提问:https://blog.qyliu.top
如果有任何问题,请提 issue 或者联系作者邮箱 01@liushen.fun,或者在网站中进行提问:https://blog.qyliu.top
13 changes: 13 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const config = hexo.config.hexo_safego = Object.assign({
ignore_attrs: ['data-fancybox'],
apply_containers: ['#article-container'], // 容器列表,如果为空则匹配整个body
apply_pages: ['/posts/'], // 生效页面路径列表
exclude_pages: ['/link/index.html'], // 排除页面路径列表
domain_whitelist: ["example.com"], // 域名白名单列表
darkmode: false, // 设置为true为暗色模式
avatar: "https://fastly.jsdelivr.net/gh/willow-god/hexo-safego@latest/lib/avatar.png",
Expand Down Expand Up @@ -37,6 +38,18 @@ if (config.enable) {
console.log("[hexo-safego]", "当前页面路径:", currentPath);
}

const isPathInExcludePages = Array.isArray(config.exclude_pages) && config.exclude_pages.some(page => {
const normalizedPage = '/' + page.replace(/^\//, '');
return currentPath.startsWith(normalizedPage);
});

if (isPathInExcludePages) {
if (config.debug) {
console.log("[hexo-safego]", "当前页面路径在 exclude_pages 列表中,跳过链接处理。");
}
return htmlContent;
}

const applyPages = Array.isArray(config.apply_pages) && config.apply_pages.length > 0 ? config.apply_pages : ["/"];
const isPathInApplyPages = applyPages.some(page => {
const normalizedPage = '/' + page.replace(/^\//, ''); // 确保 page 以斜杠开头
Expand Down

0 comments on commit 808cd3f

Please sign in to comment.