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

yuque-hexo-with-cdn

v1.2.2

Published

A downloader for articles from yuque with imgCdn

Downloads

9

Readme

yuque-hexo-with-cdn

NPM version build status Test coverage David deps npm download

A downloader for articles from yuque(语雀知识库同步工具) 本插件改造自yuque-hexo

Usage

Premise

建议使用 Node.js >= 12

事先拥有一个 hexo 项目,并在 package.json 中配置相关信息,可参考 例子

Config

配置 YUQUE_TOKEN

出于对知识库安全性的调整,使用第三方 API 访问知识库,需要传入环境变量 YUQUE_TOKEN,在语雀上点击 个人头像 -> 设置 -> Token 即可获取。传入 YUQUE_TOKEN 到 yuque-hexo 的进程有两种方式:

  • 设置全局的环境变量 YUQUE_TOKEN
  • 命令执行时传入环境变量
    • mac / linux: YUQUE_TOKEN=xxx yuque-hexo sync
    • windows: set YUQUE_TOKEN=xxx && yuque-hexo sync

配置 图床TOKEN(可选)

语雀的url存在防盗链的问题,直接部署可能导致图片无法加载。 如果需要语雀URL上传到图床中并替换原链接,就需要配置上传密钥。

访问图床的密钥管理获取密钥,然后传入密钥到yuque-hexo

  • 腾讯云API密钥管理

  • 阿里云API密钥管理

  • 七牛云API密钥管理

  • 在设置YUQUE_TOKEN的基础上配置SECRET_ID和SECRET_KEY

  • 命令执行时传入环境变量

    • mac / linux: YUQUE_TOKEN=xxx SECRET_ID=xxx SECRET_KEY=xxx yuque-hexo sync
    • windows: set YUQUE_TOKEN=xxx SECRET_ID=xxx SECRET_KEY=xxx && yuque-hexo sync

配置知识库

package.json

{
  "name": "your hexo project",
  "yuqueConfig": {
    "postPath": "source/_posts/yuque",
    "cachePath": "yuque.json",
    "mdNameFormat": "title",
    "adapter": "hexo",
    "concurrency": 5,
    "baseUrl": "https://www.yuque.com/api/v2",
    "login": "yinzhi",
    "repo": "blog",
    "onlyPublished": false,
    "onlyPublic": false,
    "lastGeneratePath": "lastGeneratePath.log",
    "imgCdn": {
      "enabled": false,
      "imageBed": "qiniu",
      "host": "",
      "bucket": "",
      "region": "",
      "prefixKey": ""
    }
  }
}

| 参数名 | 含义 | 默认值 | | ------------- |---------------------------| -------------------- | | postPath | 文档同步后生成的路径 | source/_posts/yuque | | cachePath | 文档下载缓存文件 | yuque.json | | lastGeneratePath | 上一次同步结束的时间戳的文件 | | | mdNameFormat | 文件名命名方式 (title / slug) | title | | adapter | 文档生成格式 (hexo/markdown) | hexo | | concurrency | 下载文章并发数 | 5 | | baseUrl | 语雀 API 地址 | - | | login | 语雀 login (group), 也称为个人路径 | - | | repo | 语雀仓库短名称,也称为语雀知识库路径 | - | | onlyPublished | 只展示已经发布的文章 | false | | onlyPublic | 只展示公开文章 | false | | imgCdn | 语雀图片转CDN配置 | | | urlReplace | 链接识别替换 | |

slug 是语雀的永久链接名,一般是几个随机字母。

imgCdn 语雀图片转图床配置说明

注意:开启后会将匹配到的所有的图片都上传到图床

| 参数名 | 含义 | 默认值 | | ------------- | ------------------------------------ | -------------------- | | enabled | 是否开启 | false | | imageBed | 选择将图片上传的图床,目前支持腾讯云(cos)、阿里云(oss)和七牛云(qiniu),默认使用七牛云 | 'qiniu' | | host | 使用七牛云图床时,需要指定CDN域名前缀 | bucket | 图床的bucket名称 | - | | region | 图床的的region | - | | prefixKey | 文件前缀 | - |

host 说明

由于七牛云默认使用CND进行图片外链访问(默认提供30天的临时域名或者添加自定义CDN域名),所以需要指定访问的域名前缀 例如:'host': http://image.1874.cool,域名后面不需要加斜杠

bucket和region说明

获取腾讯云的bucket和region,示例:{ bucket: "blog", region: "ap-guangzhou" }

获取阿里云的bucket和region,示例:{ bucket: "blog", region: "oss-cn-shenzhen" }

获取七牛云的bucket(空间)和region(机房),示例:{ bucket: "blog", region: "Zone_z2" }

七牛云机房取值: 华东(Zone_z0)华北(Zone_z0)华南(Zone_z0)北美(Zone_z0)

prefixKey 说明

如果需要将图片上传到bucket的根目录,那么prefixKey不用配置。

如果想上传到指定目录blog/image下,则需要配置prefixKey为"prefixKey": "blog/image"。

目录名前后都不需要加斜杠

urlReplace 链接替换说明

| 参数名 | 含义 | 默认值 | | ------------- | ------------------------------------ | -------------------- | | enabled | 是否开启 | false | | originalUrl | 需要替换的链接 | '' | | replaceUrl | 替换后的链接 | '' |

使用场景 说明 链接替换功能是针对于在语雀写作时插入之前文章的链接, 但是在部署到hexo博客后,在博客上点击访问时也会跳转到语雀

虽然无伤大雅,但还是提供了这个功能,让博客上跳转链接的文章依然跳博客的文章

Example:

originalUrl: 'https://www.yuque.com/1874w/1874.cool'

replaceUrl: 'https://1874.cool'

[语雀的文章](https://www.yuque.com/1874w/1874.cool/roeayv) => [博客的文章](https://1874.cool/roeayv)

Install

npm i -g yuque-hexo-with-cdn
# or
npm i --save-dev yuque-hexo-with-cdn

Sync

yuque-hexo sync

Clean

yuque-hexo clean

Npm Scripts

{
  "sync": "yuque-hexo sync",
  "clean:yuque": "yuque-hexo clean"
}

Debug

DEBUG=yuque-hexo.* yuque-hexo sync

Best practice

另外 x-cold 本人提供了一个触发 Travis CI 构建的 HTTP API 接口,详情请查看文档 (请勿恶意使用)

Notice

  • 语雀同步过来的文章会生成两部分文件;

    • yuque.json: 从语雀 API 拉取的数据
    • source/_posts/yuque/*.md: 生成的 md 文件
  • 支持配置 front-matter, 语雀编辑器编写示例如下:

    • 语雀编辑器示例,可参考原文
    tags: [hexo, node]
    categories: [fe]
    cover: https://cdn.nlark.com/yuque/0/2019/jpeg/155457/1546857679810-d82e3d46-e960-419c-a715-0a82c48a2fd6.jpeg#align=left&display=inline&height=225&name=image.jpeg&originHeight=225&originWidth=225&size=6267&width=225
    
    ---
    
    some description
    
    <!-- more -->
    
    more detail
  • 如果遇到上传到语雀的图片无法加载的问题,可以考虑开启imgCdn配置或者参考这个处理方式 yuque-hexo插件语雀图片防盗链限制的解决方案

Example

Changelog

v1.2.2

  • 新增链接替换功能

v1.2.1

  • 修复不使用图床配置时报错的问题

v1.2.0

  • 图片替换支持腾讯云图床、阿里云图床、七牛云图床

v1.1.2

  • 支持自动上传语雀图片到COS,并替换原链接