Notion2Hugo #18449
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Notion2Hugo | |
on: | |
workflow_dispatch: | |
schedule: | |
- cron: '*/15 * * * *' | |
push: | |
branches: | |
- main | |
permissions: | |
contents: write | |
pages: write | |
id-token: write | |
jobs: | |
sync: | |
name: Notion2Hugo on ubuntu-latest | |
runs-on: ubuntu-latest | |
outputs: | |
HAS_CHANGES: ${{ steps.NotionSync.outputs.updated_count !='0' }} | |
steps: | |
- name: Checkout blog and theme | |
uses: actions/checkout@v3 | |
with: | |
submodules: 'recursive' | |
fetch-depth: 0 | |
- name: Check the NOTION_SYNC_DATETIME | |
id: GetNotionSyncDatetime | |
run: | | |
NOTION_SYNC_DATETIME=$(git log -n 1 --grep="NotionSync" --format="%aI") | |
echo "NOTION_SYNC_DATETIME=$NOTION_SYNC_DATETIME" >> "$GITHUB_OUTPUT" | |
echo -e "Latest notion sync datetime:\n$NOTION_SYNC_DATETIME" | |
- name: Convert notion to markdown | |
id: NotionSync | |
uses: Doradx/notion2markdown-action@v1 | |
with: | |
notion_secret: ${{ secrets.NOTION_SECRET }} | |
database_id: ${{ secrets.NOTION_DATABASE_ID }} | |
pic_migrate: false | |
pic_bed_config: ${{ secrets.PICBED_CONFIG }} | |
pic_compress: true | |
output_page_dir: 'content/pages' | |
output_post_dir: 'content/posts' | |
clean_unpublished_post: true | |
metas_keeped: slug | |
metas_excluded: pstatus, ptype | |
# last_sync_datetime: ${{ steps.GetNotionSyncDatetime.outputs.NOTION_SYNC_DATETIME }} | |
- name: Commit & Push | |
if: steps.NotionSync.outputs.updated_count != '0' | |
uses: stefanzweifel/git-auto-commit-action@v4 | |
with: | |
file_pattern: 'content/' | |
commit_message: Automatic NotionSync. | |
# Deployment job | |
deploy: | |
runs-on: ubuntu-latest | |
environment: | |
name: github-pages | |
url: ${{ steps.deployment.outputs.page_url }} | |
env: | |
HUGO_VERSION: 0.114.0 | |
needs: sync | |
steps: | |
- name: Install Hugo CLI | |
run: | | |
wget -O ${{ runner.temp }}/hugo.deb https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_extended_${HUGO_VERSION}_linux-amd64.deb \ | |
&& sudo dpkg -i ${{ runner.temp }}/hugo.deb | |
- name: Install Dart Sass | |
run: sudo snap install dart-sass | |
- name: Checkout | |
uses: actions/checkout@v3 | |
with: | |
submodules: recursive | |
- name: Git Pull | |
run: git pull | |
- name: Setup Pages | |
id: pages | |
uses: actions/configure-pages@v3 | |
- name: Install Node.js dependencies | |
run: "[[ -f package-lock.json || -f npm-shrinkwrap.json ]] && npm ci || true" | |
- name: Build with Hugo | |
env: | |
# For maximum backward compatibility with Hugo modules | |
HUGO_ENVIRONMENT: production | |
HUGO_ENV: production | |
run: | | |
hugo \ | |
--minify \ | |
--baseURL "${{ steps.pages.outputs.base_url }}/" | |
- name: Upload artifact | |
uses: actions/upload-pages-artifact@v2 | |
with: | |
path: ./public | |
- name: Deploy to GitHub Pages | |
id: deployment | |
uses: actions/deploy-pages@v2 |