A tool to manage Jekyll drafts and posts (including assets) from Notion.
- Converts Notion pages to Jekyll markdown
- Extract Notion properties and uses them to create post frontmatter (e.g. Jekyll category and tags)
- Download and persist to Jekyll repo Notion block assets (e.g. images, files, PDFs)
- SEO image compatibility (compatibility depends on your Jekyll post template)
- may a couple of other things I am missing rn.
It uses the official Notion SDK to fetch data from Notion, the notion-to-md package to convert pages to markdown. Finally, it performs the necessary checks and adds the required front matter to make it a suitable Jekyll post on the blog.
It is designed to be run by a GitHub Actions workflow on a schedule or triggered by a webhook (via the repository_dispatch event).
npm run appThe script requires the following environments variables to be set:
NOTION_TOKENis the Notion integration auth web token.NOTION_DATABASE_IDis the ID of the Notion database to fetch blog posts from.RELATIVE_DATEis an int as string to determine the date of post to fetch.0means the date will be the current date;- a negative number means the date will be the current date minus the number of days;
- a positive number means the date will be the current date plus the number of days.
SITE_URLis the URL of the website, including protocol. It is used to generate thepermalinkfront matter.
Required configuration (optional when running in GitHub Action):
JEKYLL_ROOTis the root of the Jekyll directory. It is used to determine the location ofPOSTS_DIRandDRAFTS_DIRamong the other things. When running in GitHub Action, it defaults to${{ github.workspace }}.
Optional configuration, with default values:
SITE_BASEURLis the base URL of the website, appended toSITE_URLabove.DRAFTS_DIRis the Jekyll directory where drafts are stored. Defaults to_drafts.POSTS_DIRis the Jekyll directory where posts are stored. Defaults to_posts.ASSETS_DIRis the Jekyll directory where assets are stored. Defaults toassets.PUBLISH_TO_POSTSis a boolean to determine where converted pages should be published to. Iftrue, toPOSTS_DIRdirectory. ToDRAFTS_DIRotherwise.NOTION_TO_JEKYLL_USERis the user used to filter out pages published by this app. This to avoid infinite loops. Defaults tonotion-to-jekyll. It must exist in Notion.NOTION_PAGE_TYPEis the type of pages to fetch. Defaults toBlog post. It must exist in Notion.NOTION_READY_STATUSis the status used to filter out pages that are ready to be published. Defaults toReady. It must exist in Notion.NOTION_DONE_STATUSis the status used to filter out pages that are already published. Defaults toDone. It must exist in Notion.
The script can be run as a step in a GitHub Actions workflow. For example:
- name: Notion to Jekyll
uses: pirafrank/notion-to-jekyll@v1
id: notion_to_jekyll
with:
notion-token: ${{ secrets.NOTION_TOKEN }}
notion-database-id: ${{ vars.NOTION_TO_JEKYLL_DATABASE_ID }}
publish-to-posts: ${{ vars.NOTION_TO_JEKYLL_PUBLISH_TO_POSTS }}
relative-date: ${{ vars.NOTION_TO_JEKYLL_RELATIVE_DATE }}
site-url: "https://fpira.com"
assets-dir: "static/postimages"The action outputs the following variables:
- name: Print output variables
env:
# string with space-separated list of changed or added files
CHANGED: ${{ steps.notion_to_jekyll.outputs.changed }}
# string with space-separated list of deleted files
DELETED: ${{ steps.notion_to_jekyll.outputs.deleted }}
# boolean to string, 'true' if the script is running in dry-run mode
DRY_RUN: ${{ steps.notion_to_jekyll.outputs.dry-run }}
run: |
echo "CHANGED=$CHANGED"
echo "DELETED=$DELETED"
echo "DRY_RUN=$DRY_RUN"Check the action.yml file for more configuration info.
Tip: use it in a scheduled workflow, or in one with a repository_dispatch event. This allows you to make it run periodically, or to trigger the workflow via a webhook.
on:
repository_dispatch:
types: notion-to-jekyllMIT