Coder Social home page Coder Social logo

mm0202 / push-to-hatenablog Goto Github PK

View Code? Open in Web Editor NEW
27.0 2.0 9.0 16 KB

GitHubとはてなブログの連携用環境。GitHubに記事の編集内容をプッシュするとはてなブログの記事も更新されます。

License: MIT License

Dockerfile 21.68% Shell 78.32%

push-to-hatenablog's Introduction

push-to-hatenablog

GitHubとはてなブログの連携用環境。GitHubに記事の編集内容をプッシュするとはてなブログの記事も更新されます。

セットアップ

GitHubリポジトリの追加

はてなブログ記事の管理用にGitHubリポジトリを作成してください。

blogsync.yamlの追加

blogsync.example.yamlblogsync.yamlに変更して、ドメイン名やユーザ名を書き換えてください。
ローカル環境から記事を新規追加するために使用します。

blogsync.yamlについては、以下のページを参照してください。

x-motemen/blogsync #Configuration

Secretの追加

GitHubリポジトリに以下の2つのSecretを追加してください。
GitHubアクションで記事を更新するために使用します。

  • DOMAINという名前でSecretを追加してください。値にはブログのドメイン名を設定してください。
  • BSYという名前で以下のような値のSecretを追加してください。
[ブログのドメイン]:\n
  username: [ユーザ名]\n
  password: [AtomPubのAPIキー]\n
default:\n
  local_root: entries

※ Secretsの追加はGitHubリポジトリページ/Settings/Secretsから設定できます。詳細は以下のページを参照してください。

暗号化されたシークレットの作成と保存 #暗号化されたシークレットの作成

はてなブログからの記事取得

既存記事をはてなブログから取得する場合は、domain変数を指定してから、masterブランチで以下のコマンドを実行してください。

docker-compose run --rm blogsync pull ${domain}

はてなブログの更新はmasterブランチからの差分が対象となります。

記事数が多いとはてなブログの更新に時間がかかるため、masterブランチで記事を取得・コミットして、ブログの更新を回避してください。

特に初回の記事取得など記事数が多い場合はmasterブランチで取得するようにしてください。

新しい記事の追加

pathdomain変数を設定して、以下のコマンドを実行するとはてなブログとローカルに下書きが追加されます。

docker-compose run --rm blogsync post --title=draft --draft --custom-path=${path} ${domain} < draft.md

編集した記事の更新

編集した記事ファイルをGitHubへプッシュすると、GitHubアクションによってmasterブランチからの差分がはてなブログでも更新されます。

GitHubアクションの設定は以下を確認してください。

.github/workflows/push.yml

※ masterブランチからの差分が更新対象となるため、masterブランチで記事ファイルを編集しても記事の更新は実行されません。master以外のブランチで編集してください。

Slack通知設定

.github/workflows/push.ymlの調整

Slackに更新ワークフローの結果を通知する場合は、.github/workflows/push.yml内の以下のコメントアウトを解除してください。

# - name: notify to slack
#   uses: mm0202/action_slack-notify@master
#   if: always()
#   env:
#     SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}

Secretの追加

GitHubリポジトリページ/Settings/Secretsから以下のSecretを追加してください。

key value
SLACK_WEBHOOK_URL Incoming Webhookで指定されたWebhook URL

scriptsディレクトリについて

scriptsディレクトリに記事の取得、投稿スクリプトを設置しています。

scripts内のスクリプトを使用する場合は、.envファイルを作成してDOMAIN=[ブログのドメイン]を追加してください。

記事の取得

ルートディレクトリでscripts/pull.shを実行してください。

npm(またはyarn)環境がある場合は、npm run pull(またはyarn run pull)でも記事を取得できます。

記事の投稿

scripts/pull.shcustom_path=[custom_path]の部分に投稿する記事のカスタムパスを設定して、ルートディレクトリでscripts/pull.shを実行してください。

npm(またはyarn)環境がある場合は、npm run push(またはyarn run push)でも記事を取得できます。

push-to-hatenablog's People

Contributors

mm0202 avatar turusuke avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

push-to-hatenablog's Issues

docker-compose 実行時に go get が失敗する

❯ docker-compose run --rm blogsync pull blog.framinal.life

Creating network "framinal-blog_default" with the default driver
Building blogsync
Step 1/3 : FROM golang
latest: Pulling from library/golang
4948a51a9a3f: Pull complete
b4da1b3775b3: Pull complete
6efc1b20f435: Pull complete
4c81e9b9b636: Pull complete
cba7ab2dd679: Pull complete
3ba0ec045e9d: Pull complete
0a317f9f8ea9: Pull complete
Digest: sha256:54184d6d892f9d79dd332a6794bb11085c3f8b31f8be8e0911bed4df80044c93
Status: Downloaded newer image for golang:latest
 ---> 05e38b13b7e5
Step 2/3 : RUN go get github.com/x-motemen/blogsync
 ---> Running in e48640ad8a89
go: go.mod file not found in current directory or any parent directory.
        'go get' is no longer supported outside a module.
        To build and install a command, use 'go install' with a version,
        like 'go install example.com/cmd@latest'
        For more information, see https://golang.org/doc/go-get-install-deprecation
        or run 'go help get' or 'go help install'.

go get だと動かないので go install にしたところ動くようになりました。

FROM golang

- RUN go get github.com/x-motemen/blogsync
+ RUN go install github.com/x-motemen/blogsync@latest

ENTRYPOINT [ "blogsync" ]
❯ docker-compose run --rm blogsync pull blog.framinal.life

Building blogsync
Step 1/3 : FROM golang
 ---> 05e38b13b7e5
Step 2/3 : RUN go install github.com/x-motemen/blogsync@latest
 ---> Running in 68a567d2c345
go: downloading github.com/x-motemen/blogsync v0.12.1
go: downloading github.com/motemen/go-wsse v0.0.0-20141201105324-13a083a10e32
go: downloading github.com/motemen/go-colorine v0.0.0-20180816141035-45d19169413a
go: downloading github.com/motemen/go-loghttp v0.0.0-20170804080138-974ac5ceac27
go: downloading github.com/urfave/cli/v2 v2.11.1
go: downloading gopkg.in/yaml.v2 v2.4.0
go: downloading github.com/motemen/go-nuts v0.0.0-20220604134737-2658d0104f31
go: downloading github.com/daviddengcn/go-colortext v1.0.0
go: downloading github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673
go: downloading github.com/cpuguy83/go-md2man/v2 v2.0.2
go: downloading github.com/russross/blackfriday/v2 v2.1.0
Removing intermediate container 68a567d2c345
 ---> e3722773b81d
Step 3/3 : ENTRYPOINT [ "blogsync" ]
 ---> Running in 99a52030039a
Removing intermediate container 99a52030039a
 ---> 5a92d7da349e

Successfully built 5a92d7da349e
Successfully tagged framinal-blog_blogsync:latest
WARNING: Image for service blogsync was built because it did not already exist. To rebuild this image you must use `docker-compose build` or `docker-compose up --build`.
Creating framinal-blog_blogsync_run ... done
       GET ---> https://blog.hatena.ne.jp/lirlia/blog.framinal.life/atom/entry
       200 <--- https://blog.hatena.ne.jp/lirlia/blog.framinal.life/atom/entry
       GET ---> https://blog.hatena.ne.jp/lirlia/gintec.hatenablog.com/atom/entry?page=1670209098
...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.