Ruby scripts for fetching, posting, and updating blog entries on Hatena Blog using the AtomPub API.
- Fetch blog posts by URL (date-based or entry ID format)
- Extract metadata: title, content, categories, draft status, entry ID
- Multiple output formats (full, raw markdown, title, datetime, URL)
- Time tolerance matching for date-based URLs (±1 hour)
- Post new blog entries from Markdown files
- Draft/publish mode support
- Update existing blog entries by ID or URL
- Preserve or modify categories and publication datetime
- Draft/publish mode support
- Ruby (see
.ruby-version) - Bundler
- Hatena Blog API credentials
git clone https://github.com/shifumin/hatena-blog-atom-ruby.git
cd hatena-blog-atom-ruby
bundle installSet the following environment variables:
export HATENA_ID='your-hatena-id'
export HATENA_BLOG_ID='your-subdomain.hatenablog.com'
export HATENA_API_KEY='your-api-key'| Variable | Description | Example |
|---|---|---|
HATENA_ID |
Your Hatena ID | your-hatena-id |
HATENA_BLOG_ID |
Your blog domain | your-subdomain.hatenablog.com |
HATENA_API_KEY |
API key from blog settings | (see below) |
- Log in to Hatena Blog
- Go to:
https://blog.hatena.ne.jp/{HATENA_ID}/{BLOG_ID}/config/detail - Scroll to "AtomPub" section
- Click "APIキーを表示" (Show API Key)
Fetch a blog entry by URL:
ruby hatena_blog_fetcher.rb [OPTIONS] URL| Option | Description |
|---|---|
-r, --raw |
Output raw Markdown content only |
-t, --title |
Output title only |
-d, --date |
Output publication datetime only |
-u, --url |
Output URL only |
-h, --help |
Display help message |
- Date-based:
https://example.hatenablog.com/entry/2024/01/01/123456 - Entry ID:
https://example.hatenablog.com/entry/20240101/1234567890
# Full entry information
ruby hatena_blog_fetcher.rb https://example.hatenablog.com/entry/2024/01/01/123456
# Raw Markdown only
ruby hatena_blog_fetcher.rb -r https://example.hatenablog.com/entry/2024/01/01/123456
# Title only
ruby hatena_blog_fetcher.rb -t https://example.hatenablog.com/entry/2024/01/01/123456============================================================
タイトル: サンプル記事タイトル
投稿日時: 2024-01-01 12:34:56
URL: https://example.hatenablog.com/entry/2024/01/01/123456
カテゴリ: Ruby, API
下書き: no
エントリーID: 13574176438046791234
============================================================
本文(Markdown):
------------------------------------------------------------
# 見出し
本文のMarkdownコンテンツ
============================================================
Post a new blog entry from a Markdown file:
ruby hatena_blog_poster.rb [OPTIONS]| Option | Description |
|---|---|
-t, --title TITLE |
Article title (required) |
-f, --file FILE |
Markdown file path (required) |
-p, --publish |
Publish immediately (default: draft) |
-h, --help |
Display help message |
# Post as draft
ruby hatena_blog_poster.rb -t "My Article" -f article.md
# Publish immediately
ruby hatena_blog_poster.rb -t "My Article" -f article.md -pUpdate an existing blog entry:
ruby hatena_blog_updater.rb [OPTIONS]| Option | Description |
|---|---|
-u, --url URL |
Entry URL (mutually exclusive with -i) |
-i, --id ID |
Entry ID (mutually exclusive with -u) |
-t, --title TITLE |
Article title (required) |
-f, --file FILE |
Markdown file path (required) |
-p, --publish |
Publish immediately (default: draft) |
-c, --categories CATEGORIES |
Categories (comma-separated) |
--updated DATETIME |
Publication datetime (ISO8601 format) |
-h, --help |
Display help message |
# Update by entry ID
ruby hatena_blog_updater.rb -i 13574176438046791234 -t "Updated Title" -f content.md
# Update by URL
ruby hatena_blog_updater.rb -u https://example.hatenablog.com/entry/2024/01/01/123456 \
-t "Updated Title" -f content.md
# Update and publish with categories
ruby hatena_blog_updater.rb -i 13574176438046791234 -t "Updated Title" -f content.md \
-p -c "Ruby,API"
# Preserve publication datetime
ruby hatena_blog_updater.rb -i 13574176438046791234 -t "Updated Title" -f content.md \
--updated "2024-01-01T12:34:56+09:00"