patrickmfsd

Migrating From Jekyll to Publish

I recently migrated my site from Jekyll to Publish. This gave me the opportunity to redesign aspects of my site, add new pages and move my blog. In this post I will talk about some of the processes and steps I did to move my site to Publish and deploy to Github Pages using Github Actions.

Publish is a Static Website builder built for Swift Developers, by John Sundell. Publish allows you to generate a site using Swift and supports themes and plugins. I'm currently using the Splash Publish Plugin which adds Syntax Highlighting to the site.


Site Structure Overview

├── Package.swift
├── Package.resolved
├── Content/
│   ├── posts/
│   ├── projects/
│   ├── apps.md
│   ├── index.md
│   └── resume.md
├── Output/
├── Resources/
│   ├── Portfolio/
│   │   └── styles.css
│   └── images/
│       ├── projects/
│       │   └── .../
│       │       └── ...
│       └── favicon.png
└── Sources/
    └── Portfolio/
        ├── DateFormatter.swift
        ├── main.swift
        └── portfolio-theme.swift

Blog Migration

I used this opportunity to migrate some of my posts from my Medium blog, this was a multi stage process:

  1. Downloading a copy of my information as .zip file from medium exporter tool, which had a copy of posts under posts\ as .html files.
  2. Converting the .html files to .md files, using a terminal tool called pandoc.
  3. Once converted I went through the converted .md files to fix formatting and and image links.

Deploying to Github Pages

The site is deployed via Github Pages using a Github Action Workflow. The workflow consists of the the trigger and the workflow job.

Trigger

The workflow trigger involves watching the develop branch for any changes, if there is a change on develop it then runs the deploy job.

on:
  push:
    branches: 
    - develop

Job

The deploy job, contains several steps. Checkout which checks out develop, Setup Publish which downloads and sets up Publish, Generate Site runs publish-cli generate and Deploy. A snippet of the setup stages is bellow.

steps:
  - name: Checkout
    uses: actions/checkout@v2

  - name: Setup Publish
    run: |
      cd ${HOME}
      git clone --depth=1 https://github.com/JohnSundell/Publish.git
      cd ./Publish
      swift build -c release
      echo "::add-path::${HOME}/Publish/.build/release"
      
  - name: Generate Site 
    run: publish-cli generate

Deploy Step

The last step of the workfow job is deploying the site to the master branch, this step uses peaceiris/actions-gh-pages@v2 (which can be found here).

   - name: Deploy Site
    uses: peaceiris/actions-gh-pages@v2
    env:
      ACTIONS_DEPLOY_KEY: ${{ secrets.ACTIONS_DEPLOY_KEY }}
      PUBLISH_BRANCH: master
      PUBLISH_DIR: ./Output

Actions Deploy Key

To create the Actions_Deploy_Key run the following command in Terminal.

ssh-keygen -t rsa -b 4096 -C "$(git config user.email)" -f gh-pages -N ""

This will create two files gh-pages.pub which is the public key and gh-pages which is the private key. Once the keys are created:

  1. Navigate to GitHubs Repo Settings > Deploy Keys, and copy the public key you created to the key text box and tick the "Allow write access" checkbox.
  2. Navigate to Secrets settings. Enter ACTIONS_DEPLOY_KEY to the title and copy the contents of the private key file to value text box.

There are still a few changes and additions I am planning to make in the future to the site, like new pages and tweaking layouts. Migrating the site to Publish has been a good experience and I'm excited to see where Publish goes in the future.

Tagged with: