DEV Community

Pacharapol Withayasakpunt
Pacharapol Withayasakpunt

Posted on • Edited on • Originally published at polv.cc

I turned my website into a template, mostly by git tricks

This was created by

  • Move personalized information from every folders to some very specific folders
/blog/**/*.md # Any deep nesting is possible
/media/
/theme.yml
Enter fullscreen mode Exit fullscreen mode
  • Separate to two repos, of theme, and of content
# Shared commands
brew install git-filter-repo # https://github.com/newren/git-filter-repo/blob/main/INSTALL.md
Enter fullscreen mode Exit fullscreen mode
# Content repo
git remote add upstream <GIT_UPSTREAM_URL>
git fetch upstream
git pull upstream master
git remote remove upstream
git filter-repo --path 'blog/**/*.md' --path 'media/' --path theme.yml --force # and other related content folders in the past
git push origin master
Enter fullscreen mode Exit fullscreen mode
# Theme repo
git remote add upstream <GIT_UPSTREAM_URL>
git fetch upstream
git pull upstream master
git remote remove upstream
git filter-repo --invert-paths --path 'blog/**/*.md' --path 'media/' --path theme.yml --force # and other related content folders in the past
echo '/content/' >> .gitignore
git push origin master
Enter fullscreen mode Exit fullscreen mode
  • Then, add environmental variables to Netlify as needed. After, if you working repo git is connected to Netlify
# Working repo
git remote add upstream <GIT_THEME_URL>
git fetch upstream
git switch -c dev upstream/master
git clone <GIT_CONTENT_URL> content
git push origin dev
git branch -D master
git checkout master
git push -f origin master
Enter fullscreen mode Exit fullscreen mode

I also summarized this on GitHub's wiki.

GitHub logo patarapolw / nuxt-blog-template

Nuxt.js blog template, with working version at https://www.polv.cc

nuxt-blog-template

Commitizen friendly

Features

  • Nuxt.js with full TypeScript (nuxt-ts)
  • Markdown-it extended with Pug and LiquidJS
  • CSS is allowed
  • Images in markdown are optimized as WebP format
  • Separated content and theme. Either or both can be private.
  • Searchable via lunr.js
  • Easy to deploy on Netlify

Initialization

  • There are two ways, forking, and using upstream
  • Add your contents to /content/, or process.env.CONTENT_PATH
CONTENT_PATH=<PATH_TO_YOUR_CONTENT>
Enter fullscreen mode Exit fullscreen mode

content folder structure

/post/**/*.md
/media/
/theme.yml
Enter fullscreen mode Exit fullscreen mode

/theme.yml structure

Since it is linted and typed with zod, it is best to read the schema here.

Markdown structures

It is Markdown with YAML Frontmatter.

---
title: string
date: string | undefined (parsable by dayjs)
image: string | undefined
tag: array of string | undefined
(Additional keys can be added, but it won't be parsed)
---
Put your excerpt here
<!-- excerpt -->
Put your remaining content here
Enter fullscreen mode Exit fullscreen mode

You might…

Of course, this is used in a real website -- https://www.polv.cc and the lighthouse score (https://web.dev/measure/) is quite commendable, I think; although there are indeed rooms to improve.

Lighthouse score

Top comments (0)