Skip to content

A GitHub Action for fetch pages which saved by Notion Web Clipper.

License

Notifications You must be signed in to change notification settings

RyoJerryYu/notion-clipper-archiver

Use this GitHub action with your project
Add this Action to an existing workflow or create a new one
View on Marketplace

Repository files navigation

typescript-action status

Notion Clipper Archiver

This action archives the notion pages in a notion database to a json file.

This action aims to be well integrated with Notion API and Notion Web Clipper.

Example usage

This action work with the official Notion API, so you need to create a new integration in Notion and get the token before using this action. You can find the detailed instructions here.

This action will fetch the notion pages properties in a database, and save them to a json file. Generally, you would combine this action with some other actions to handle the json file.

Here is an example for use this action with Upload Artifact action to upload the json file to Github Actions.

- name: Archive Notion Clips
  uses: RyoJerryYu/notion-clipper-archiver@v1
  id: notion_clipper_archiver
  with:
    notion_token: ${{ secrets.NOTION_TOKEN }}
    database_id: ${{ secrets.DATABASE_ID }}
    save_dir: ./data
    file_name: clips.json
- name: Upload clips.json
  uses: actions/upload-artifact@v3
  with:
    name: results
    path: ${{ steps.notion_clipper_archiver.outputs.save_path }}

The json file would look like this:

{
  "achived_at": "2021-02-16T07:42:00.000Z",
  "pages": [
    {...},
    {...},
    {...}
  ]
}

Each page should be saved with the following format:

{
  "id": "uuid",
  "title": "Page Title",
  "url": "url",
  "tags": ["tag1", "This field is optional"],
  "created_time": "2023-02-16T07:42:00.000Z"
}

Inputs

notion_token

required The Notion token. You can get it by create a new integration in Notion.

database_id

required The id of the database where your clips are stored. You should share the database with the integration you created. More information about database id can be found here.

save_dir

required The directory where the json file will be saved.

save_file

required The name of the json file.

need_content

optional Whether the clips should contain content. Default is false.

By default, this action does not fetch the page content. If you want to fetch the page content, you can set the need_content input to true.

- name: Archive Notion Clips
  uses: RyoJerryYu/notion-clipper-archiver@v1
  with:
    need_content: true
    ...

The page content will be saved as a markdown string in the content field. You can use remark plugins or something else to handle the markdown string.

{
  "id": "uuid",
  "title": "Page Title",
  "url": "url",
  "tags": ["tag1", "This field is optional"],
  "created_time": "2023-02-16T07:42:00.000Z",
  "content": "# Page Content\n\nParagraph\n\n## Sub..."
}

contains_tags and not_contains_tags

optional The tags that the clips should contain or should not contain.

If contains_tags not specified, all tags can be contained. If not_contains_tags not specified, no tags can not be contained.

Since Github Actions does not support array input, you should use multiple lines input to specify each tag in a line.

- name: Archive Notion Clips
  uses: RyoJerryYu/notion-clipper-archiver@v1
  with:
    contains_tags: |
      tag1
      tag2
    not_contains_tags: |
      tag3
      tag4
    ...

For the above example, only the pages that satisfy the following conditions will be saved:

(
  (pages contains tag1)
  or 
  (pages contains tag2)
)
and
(
  (pages not contains tag3)
  and
  (pages not contains tag4)
)

Outputs

save_path

The path of the json file. You can use this output to upload the json file to somewhere or use it in other actions.