Introduction

This article is part of the Hexo blog setup guide series version 1.1, focusing on the process of synchronizing Notion content to a Hexo blog using Elog. For a comprehensive overview of the entire blog setup series, please refer to the detailed guide: Hexo Blog Building Guide: Systematic Solutions and Detailed Construction Process.

Overall Process

  • The process is as follows:

Overall process

Explanation:

  • The process consists of three main stages: preparation, Notion configuration, and local Hexo blog configuration.
  • The Notion configuration involves creating a Notion database and enabling access to it via a token for content updates.
  • The local Hexo blog configuration focuses on initializing Elog and establishing the connection between Notion and Hexo.

Preparation

1
2
3
4
5
# Installation
npm install @elog/cli -g

# Check version
elog --version

Notion Configuration

Create an Integration Token

Refer to the official Notion documentation: https://developers.notion.com/docs/create-a-notion-integration#create-your-integration-in-notion.

Access the integrations section here: https://www.notion.so/profile/integrations.

  • The process is as follows:

Create Integration Token Process

Duplicate the Created Notion Database

You can refer to the elog-hexo-template to create a copy of the database or add necessary properties to an existing Notion database.

Connect the Database to the Newly Created Integration

  • Click on the “…” in the upper right corner, select “Connections,” then choose the previously set token (for example: hexo-elog-token-en), and click “Confirm.” This will successfully connect the current database with the token.

Connect the Database to the Newly Created Integration

Record Token and Database ID

(1)Record Token

For example:

Record Token

(2)Record Database ID

For example:

Record Database ID

Local Hexo Blog Configuration

Initialize Elog in the Hexo Project

1
2
# Initialize Elog configuration file
npx @elog/cli init

Configure Token and Database ID

In elog.env, configure your token and database ID.

Configure Token and Database ID

Configure Synchronization Rules in elog.config.js

In elog.config.js, set up synchronization rules:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
module.exports = {
write: {
platform: 'notion',
notion: {
token: process.env.NOTION_TOKEN,
databaseId: process.env.NOTION_DATABASE_ID,
filter: true,
frontMatter: {
enable: true,
include: ['title', 'categories', 'tags', 'description', 'status', 'cover', 'urlname', 'date'],
},
},
},
deploy: {
platform: 'local',
local: {
outputDir: './source/_posts/',
filename: 'title',
format: 'matter-markdown',
frontMatter: {
enable: true,
include: ['title', 'categories', 'tags', 'description', 'status', 'cover', 'urlname', 'date'],
},
},
},
};

Execute Synchronization

Run the synchronization command:

1
npx @elog/cli sync -e .elog.env

Synchronization Results

If successful, you will see a message indicating that synchronization is complete:

1
2
3
4
5
6
7
8
9
10
11
12
13
(base) $ npx @elog/cli sync -e .elog.env
Environment variables specified for reading from env file.
Full update initiated as no cache was found.
Fetching document list, please wait...
Total documents: 2
Documents to download: 2
Starting document download...
Downloading document 1/2 test
Downloading document 2/2 Start my journey as an indie hacker
Downloaded documents: 2
Generated documents test.md
Generated documents Start my journey as an indie hacker.md
Task completed! Synchronization complete!

Preview the Blog

  • Preview your blog locally to verify that Notion content has been synchronized to your Hexo blog.
  • If it meets your requirements, you can proceed with online deployment; if there are issues, make targeted adjustments.

Daily Operations

Optimizing Notion Content Synchronization

  • To synchronize line breaks within cells, use Markdown format <br>. Direct line breaks in Notion may cause content to jump to a new line instead of staying within the cell.
  • For links with titles, first insert the link in Notion, then edit it to manually define the link’s title.
  • For images with titles, insert an image in Notion and edit its caption to define its title manually.

Management Methods for Notion + Hexo

  • Use scattered time to record in Notion and regularly synchronize in batches using Elog for enhanced efficiency.

Important Notes

  • If you modify titles in Notion, it will generate a new Markdown file upon synchronization with Hexo. Be sure to clean up any old Markdown files promptly.

Conclusion

By following these configurations, you can successfully synchronize Notion content quickly to your Hexo blog. This process not only enhances content management efficiency but also adds flexibility and convenience to your blogging experience.

As we use this setup in practice, we will continually refine synchronization details to meet various needs and scenarios. Stay tuned for updates as we regularly publish new tips and best practices to help you better utilize Notion and Hexo for content management.

References

https://elog.1874.cool/

https://github.com/LetTTGACO/elog