Using Obsidian as a CMS

Okay I think I have this working well now.

I've created a blog site using NextJS and Content Layer, and placed an Obsidian vault in the repo to act as my content source. I broke this vault off into its own Git submodule and placed it in a private GitHub repo.

When I push to the parent repository the Netlify site builds just like normal. When I push content changes within the submodule up, it triggers a GitHub Action that I set up which daisy chains a commit to the parent repo just to update the submodule's commit reference to the latest. This extra commit triggers a build in Netlify in the normal manner. Here is my GitHub action for the private repo, which I adapted from this Stack Overflow post1:

name: Send submodule updates to parent repo 

on:
 push:
 branches:
  - main

jobs:
  update:
  runs-on: ubuntu-latest
  steps:
    - uses: actions/checkout@v2
      with:
        repository: franknoirot/blog-v2
        submodules: true
        token: ${{ secrets.PRIVATE_TOKEN_GITHUB }}
    
	- name: Pull & update submodules recursively
      run: |
        git submodule update --init --recursive
        git submodule update --recursive --remote
    - name: Commit changes
      run: |
        git config user.email "actions@github.com"
        git config user.name "GitHub Actions - update submodules"
        git add --all
        git commit -m "Fresh Obsidian content in personal-notes" || echo "No changes to commit"
        git push

A little mind-bending, but what it means is that I can take notes like normal in Obsidian, backing up my notes as I like, especially with the convenience of the wonderful Obsidian Git plugin at my fingertips.

If I want to publish a note or other thought I simply move the note into the appropriate folder and make sure it has the right fields in its frontmatter, then when I back it up the changes in the public directory will be pushed, triggering a rebuild of my website!

All of this effort was to have my website be a true subset of my personal Obsidian knowledge graph, the parts of my second brain that are ready to show the world, without losing any of the niceties of working in Obsidian.

Footnotes

  1. Shoutout to user @GILO for commenting in that you need to add submodules: true for this to work 🙌🏻, I thought I was out of luck for sure.

Other content that links to this