Blot.imの連携先をGoogle DriveからGitに変更した

Blot.imの連携先をGoogle DriveからGitに変更した

2022年9月9日
約 2分で読める
#ブログ#Obsidian#Blot.im#Git#Github

Blot.imの連携先をGoogle DriveからGitに変更した

少し前に書いたけど、このブログはBlot.imで作られている。Blot.imについては以下の記事を参照。

Google DriveからGitに移行した理由

一応運用できていたのだけど、Google DriveのせいなのかBlotのせいなのか分からないが、

  • ファイル作成後にファイル名を変更すると、変更前、変更後の二つのファイルがBlot.im上にアップロードされてしまうことがある
  • 謎の .md.html ファイルが作成されてしまうことがある

等々、同期周りで挙動がおかしくなる時があった。

なので、Gitに移行してみることにした。さらにGithubと一緒に使うことでGithub上で簡単な変更等をできるようになったのでさらに便利になった気がする。

構成

Githubを使う理由

Githubを使うことによって以下のメリットがある。

  • Github上でブラウザから簡単な編集なら可能 (プレビューもできるし割と便利)
  • Issue管理、Projects管理とかもできるので何かと便利

と思ったより、書き出したらメリット少なかったけど間にGithubを噛ませることにしてみたけど。

Github Actionsを使ったBlot.imへの更新方法

Githubから、Blot.im上のGitに都度更新していく必要があるのだけど、それはGithub Actionsを使って行うことにした。

本当は、リポジトリ同志でうまく同期させる方法があればいいのだけど、うまくできなかったので、Blot.im上のファイルを一旦消してしまって無理やり同期させる方法にしてしまった。

一応これでうまく動いている。

Github Actionsで色々と処理を行うことができるので、何かと便利な気がする。

# This is a basic workflow to help you get started with Actions

name: Publishing

# Controls when the workflow will run
on:
  # Triggers the workflow on push or pull request events but only for the "master" branch
  push:
    branches: [ "master" ]

  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:
env: 
  BLOT_REPO_NAME: ${{ secrets.BLOT_REPO_NAME }} 
  BLOT_REPO_URL: ${{ secrets.BLOT_REPO_URL }}
  BLOT_USER_EMAIL: ${{ secrets.BLOT_USER_EMAIL }}
  BLOT_USER_NAME: ${{ secrets.BLOT_USER_NAME }}

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
  # This workflow contains a single job called "build"
  build:
    # The type of runner that the job will run on
    runs-on: ubuntu-latest

    # Steps represent a sequence of tasks that will be executed as part of the job
    steps:
      # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
      - name: Check out repository
        uses: actions/checkout@v3
        with: 
          path: github
      - name: Check out from BLOT
        run: git clone $BLOT_REPO_URL
      - name: Sync between github & blot
        run: |
          rm -fr $BLOT_REPO_NAME/*
          cp -fr github/* $BLOT_REPO_NAME/
      - name: Commit & Push
        run: |
          cd $BLOT_REPO_NAME
          git config user.email $BLOT_USER_EMAIL
          git config user.name $BLOT_USER_NAME
          git add .
          git commit -m "changes"
          git push