Xlenco

Xlenco

github
zhihu
email

Yuqing rich text writing automatically deployed to Hexo

This article is written by Yuque

"Yuque" is a "knowledge creation tool" incubated by Ant Financial, an innovative product under the concept of Experience Technology, and has become the standard for over 50,000 Alibaba employees for document writing and knowledge accumulation. The blogger is already a user of Yuque and accidentally discovered that Elog can synchronize Yuque articles to the local. Writing with Yuque allows for real-time rendering, and there’s no need to worry about image hosting. Without further ado, let's start the tutorial.

Migrate Blog Articles to Yuque#

Open the Yuque official website and enter the homepage, click the plus sign in the upper left corner
PixPin_2024-02-17_17-28-36.png

Next, click Import
PixPin_2024-02-17_17-28-52.png
Then select markdown format
PixPin_2024-02-17_17-29-40.png
Finally, in the markdown import configuration, select compressed file after markdown packaging
PixPin_2024-02-17_17-30-08.png
After the import is complete, the Front-matter of the file may be a bit messy, so it is recommended to manually change it.

Install Elog#

First, you need to globally install @elog/cli using npm/ cnpm / yarn / pnpm

Configure package.json#

Add @elog/cli to package.json

Initialization#

Enter the Hexo root directory and use the command to initialize:

After successful initialization, a elog.config.js configuration file and a .elog.env environment variable configuration file for local debugging will be generated in the root directory.

Configure Elog#

The official documentation provides two configuration methods: yuque (Token method) and yuque-pwd (account and password method).
If you are a Yuque member, it is recommended to choose yuque (Token method), otherwise choose yuque-pwd (account and password method).

Edit your elog.config.js file#

Configure .elog.env file#

To prevent this file from leaking during Git uploads, it is recommended to add .elog.env to .gitignore

Specific configuration depends on your setup method.
Below is the official documentation explanation.

Yuque (Token method)#

Note: According to Yuque's pricing adjustments, this method requires a Yuque premium membership to use; accounts that have previously generated tokens can still use them.
For obtaining key information and configuration process, please refer to Key Information Acquisition page.

FieldRequiredDescriptionDefault Value
tokenYesYuque Token-
baseUrlNoBase URL for Yuque API requestshttps://www.yuque.com/api/v2
loginYesPersonal path/space ID-
repoYesShort name of the Yuque repository, also known as the Yuque knowledge base path-
onlyPublicNoWhether to only retrieve public articlesfalse
onlyPublishedNoWhether to only retrieve published articlesfalse
limitNoDocument download concurrency3

baseUrl is the request path for the Yuque API.
When the knowledge base type is a personal knowledge base, no configuration is needed.
When the knowledge base type is a team knowledge base, baseUrl=https://spaceid.yuque.com/api/v2, login=spaceid, repo=the Yuque knowledge base path in the space.

Yuque (Account and Password method)#

This method does not require a Yuque membership.
Note: Using this method in non-domestic CI/CD environments, such as GitHub Workflow, will result in a large number of US IPs appearing in the Yuque backend login devices. It is currently unclear whether Yuque will have security restrictions, so please use it with caution. It is recommended to use it during local synchronization.
For obtaining key information and configuration process, please refer to Key Information Acquisition page.

FieldRequiredDescriptionDefault Value
usernameYesYuque account, usually a phone number-
passwordYesYuque password, can be bound in settings
hostNoYuque domain/team domainhttps://www.yuque.com
loginYesPersonal path/space ID-
repoYesShort name of the Yuque repository, also known as the Yuque knowledge base path-
linebreakNoWhether to maintain Yuque's line breaksfalse
onlyPublicNoWhether to only retrieve public articlesfalse
onlyPublishedNoWhether to only retrieve published articlesfalse
limitNoDocument download concurrency3

host is the Yuque domain.
When the knowledge base type is a personal knowledge base, no configuration is needed.
When the knowledge base type is a team knowledge base, host=https://spaceid.yuque.com.

Start Synchronization#

After configuration is complete, execute the local synchronization command in the root directory:

Automation Process#

Yuque + webhooks + serverless API + GitHub Actions + GitHub Pages Continuous Integration
93e5eae8d73452e3043e9845b627be8d.png Here we quote the content from the official documentation.

#

GitHub Actions#

  1. Configure the required environment variables in the Secrets and variables - Actions - Secrets section of the repository's Settings
GITHUBTOKENYour GitHub Token
YUQUE_REPOYour Yuque knowledge base path
YUQUE_LOGINYour Yuque account name (path)
YUQUE_USERNAMEYour phone number
YUQUE_PASSWORDYour Yuque password

If you are using Yuque (Token method), you can replace YUQUE_USERNAME and YUQUE_PASSWORD with YUQUE_TOKEN.

  1. Create a file named .github/workflows/Deploy Yuque-Hexo Public To Pages in the root directory and configure it according to the following process

Accessing the serverless API can trigger action deployment.

Serverless API#

For convenience, here is a free public Serverless API deployed on Vercel.
Just fill it into the Yuque Webhooks.
Yuque users without a membership can manually call this API to trigger GitHub Actions for automated building & deployment.

Yuque Webhooks#

In the Yuque knowledge base - More settings - Message push, you can configure Yuque webhooks by filling in an API link that supports POST requests (here taking the serverless API as an example). When the document is updated, Yuque will call this API for pushing.
Unfortunately, Yuque has made webhooks a paid feature.
Yuque users without a membership can manually call the API to trigger GitHub Actions for automated building & deployment.
After the knowledge base is configured with the "automatic publishing" feature, document update/publish operations will not send webhooks.
image.png

References#

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.