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-safego

v2.0.1

Published

✨Hexo plugin for safe external link redirection with base64 encoding, domain whitelisting, and support for a custom redirect page.

Downloads

170

Readme

简体中文 | English

hexo-safego

NPM 发布地址 | 详细说明文档

hexo-safego 是一个改进版的 Hexo 插件,用于处理外部链接以增强博客的安全性。该插件基于 hexo-external-link 二次开发,但其实现方式不同:原版插件通过注入 JS ,在打开网站时才处理外部链接,而 hexo-safego 则在生成静态页面时直接替换外部链接,并且提供了很多人性化的配置。

主要特性

  • 外部链接跳转:将外部链接替换为自定义的跳转页面,增加安全性。
  • 灵活配置:支持多个容器 ID、白名单域名和生效页面路径的配置。
  • Base64 编码:可选的 Base64 编码功能。
  • 调试模式:调试模式输出详细信息,便于开发和调试。
  • 自定义页面:支持设置标题、副标题、头像、暗黑模式等。

安装

在使用该插件之前,需要先安装 cheerio,Hexo 一般有这个插件,可以在 node_modules 查看,如果没有,执行:

npm install cheerio --save

然后安装 hexo-safego 插件:

npm install hexo-safego --save

配置

在 Hexo 的配置文件 _config.yml 中添加或更新以下配置:

# hexo-safego安全跳转插件
# see https://blog.qyliu.top/posts/1dfd1f41/
hexo_safego:
  enable: true  # 是否启用 hexo-safego 插件
  enable_base64_encode: true  # 是否启用 Base64 编码链接
  enable_target_blank: true  # 是否在跳转链接中添加 target="_blank"
  url_param_name: 'u'  # URL 参数名,用于生成跳转链接
  html_file_name: 'go.html'  # 跳转页面文件名
  ignore_attrs:  # 需要忽略的链接属性列表
    - 'data-fancybox'
  apply_containers:  # 容器 ID 列表,如果为空则匹配整个 body
    - '#article-container'
  domain_whitelist:  # 域名白名单列表,包含白名单中的域名的链接将被忽略
    - 'example.com'
  exclude_pages: # 排除路径列表,会排除这些页面,可以配合生效页面路径配合使用
    - '/safego_exclude_page/'
  apply_pages:  # 生效页面路径列表,只有在这些页面上才会对链接进行处理
    - '/posts/'
  avatar: https://fastly.jsdelivr.net/gh/willow-god/hexo-safego@latest/lib/avatar.png  # 头像图片链接
  title: "清羽飞扬"  # 标题
  subtitle: "安全中心"  # 副标题
  darkmode: false  # 是否启用夜间模式
  debug: false  # 是否启用调试模式,开启后会输出详细的调试信息

必要修改说明

  • domain_whitelist: 该参数为您的站点根域名。此配置使用字符串匹配,如果外链中包含您填写的字符串,则会跳过该外链不进行处理。可以设置多个域名。
  • apply_containers: 该参数为您希望处理的容器选择器。如果需要类名选择器,可以使用 .类名 进行筛选。如果希望匹配整个网站,请填写 body 或者置空 or 删除该配置项。由于我使用的是 Butterfly 主题,因此填写了 Butterfly 主题中文章部分的选择器 #article-container , 请按需设置。
  • apply_pages: 该参数指定插件生效的页面路径。如果您只希望在文章页面中使用插件,可以像示例配置中一样设置路径为 '/post/'。如果希望插件在整个网站生效,可以设置为 '/' 或者置空 or 删除该项配置。
  • avatar、title、subtitle: 请设置为您的个人信息,以提高头像显示速度。默认头像为 jsdelivr 图片,国内访问可能会影响加载速度。支持使用本地相对路径图片或网络图片链接。
  • 注意: 以上配置项中部分可能空值判断不准确,仅作为防止出现异常的处理,如果使用请尽量不要留空。如果您不需要某个配置项并希望使用默认值,请直接删除对应配置项或者设置为对应默认值。

通过以上配置,您可以更好地自定义 hexo-safego 插件的行为和外观,确保外部链接处理更加安全和符合您的需求。

配置参数说明

enable

  • 类型Boolean
  • 默认值false
  • 描述:是否启用 hexo-safego 插件。

enable_base64_encode

  • 类型Boolean
  • 默认值true
  • 描述:是否对跳转链接进行 Base64 编码。

enable_target_blank

  • 类型Boolean
  • 默认值true
  • 描述:是否在跳转链接中添加 target="_blank" 属性,建议添加,可以在新页面打开。

url_param_name

  • 类型String
  • 默认值u
  • 描述:跳转页面的 URL 参数名称。

html_file_name

  • 类型String
  • 默认值go.html
  • 描述:生成的跳转页面文件名。

ignore_attrs

  • 类型Array
  • 默认值['data-fancybox']
  • 描述:需要忽略的链接属性列表。如果链接包含这些属性,将不会被处理。

apply_containers

  • 类型Array
  • 默认值['body']
  • 描述:指定要处理的容器 ID 列表。如果为空,则匹配整个 body

domain_whitelist

  • 类型Array
  • 默认值["example.com"]
  • 描述:域名白名单列表,包含白名单中的域名的链接将被忽略。

apply_pages

  • 类型Array
  • 默认值['/']
  • 描述:生效页面路径列表,只有在这些页面上才会对链接进行处理。如果希望插件对整个网站生效,可以设置为 ['/']

exclude_pages

  • 类型Array
  • 默认值[]
  • 描述:生效页面路径列表,只有在这些页面上才会对链接进行处理,建议和apply_page搭配使用,可以更加准确的限制路径,如果不配置或置为空不会影响。

avatar

  • 类型String
  • 默认值https://fastly.jsdelivr.net/gh/willow-god/hexo-safego@latest/lib/avatar.png
  • 描述:跳转页面的头像图片链接,支持相对路径本地图片和绝对路径网络图片。

title

  • 类型String
  • 默认值网站名称
  • 描述:跳转页面的标题。

subtitle

  • 类型String
  • 默认值网站副标题
  • 描述:跳转页面的副标题。

darkmode

  • 类型Boolean
  • 默认值false
  • 描述:是否启用夜间模式。

debug

  • 类型Boolean
  • 默认值false
  • 描述:是否启用调试模式,开启后会输出详细的调试信息。

问题反馈

如果有任何问题,请提 issue 或者联系作者邮箱 [email protected],或者在网站中进行提问:https://blog.liushen.fun