LoginSignup
0
0

More than 5 years have passed since last update.

sitemap.xmlにあるURLパスを列挙・巡回するCLIツール

Last updated at Posted at 2019-03-06

TL;DR

  • sitemapathsを使えばsitemap.xmlのURLパスを列挙できるよ
  • sitemapathsを使ってワンラインでCloudFrontのキャッシュを消せるよ
  • sitemapbotを使えばsitemap.xmlのURLパス全てにHTTPリクエストできるよ

sitemapathsのシンプルな使い方

https://github.com/hareku/sitemapaths
sitemapathsは、sitemap.xmlからURLパスを列挙するCLIツールであり、以下のように使える。

$ sitemapaths https://example.com/sitemap.xml
/
/first-post
/second-post

sitemapathsでCloudFrontのキャッシュを削除

sitemapathsを使って、sitemap.xmlに記載されたURLパス全てをCloudFrontのキャッシュから削除できる。

# CloudFrontのディストリビューションIDを設定
$ CF_DISTRIBUTION_ID=ET5LGZEQ5FWA4

# sitemap.xmlのパスを列挙
$ PATHS=$(sitemapaths https://example.com/sitemap.xml)

# Invalidation(キャッシュの無効化)のリクエストを作成
$ INVALIDATION_REQUEST=$(aws cloudfront create-invalidation --distribution-id $CF_DISTRIBUTION_ID --paths $PATHS)

# InvalidationリクエストのIDを取得
$ INVALIDATION_ID=$(echo $INVALIDATION_REQUEST | jq -r '.Invalidation.Id')

# Invalidationが完了するまで待つ
$ aws cloudfront wait invalidation-completed --distribution-id $CF_DISTRIBUTION_ID --id INVALIDATION_ID

これは以下のようにワンラインで書ける。

$ CF_DISTRIBUTION_ID=ABCDEFG123
$ aws cloudfront wait invalidation-completed --distribution-id $CF_DISTRIBUTION_ID --id $(aws cloudfront create-invalidation --distribution-id $CF_DISTRIBUTION_ID --paths $(sitemapaths https://example.com/sitemap.xml) | jq -r '.Invalidation.Id')

sitemapbotでsitemap.xmlのURLを全て巡回する

https://github.com/hareku/sitemapbot
sitemapbotを使えばsitemap.xmlに記載されているURL全てにアクセスできる。
主にキャッシュを再作成する用途として使う。

$ sitemapbot https://example.com/sitemap.xml
2019/03/03 19:02:41 crawling started: https://example.com/sitemap.xml
 213 / 213 [================================================] 100.00% 11s
2019/03/03 19:02:53 crawling finished: https://example.com/sitemap.xml, success:213, error:0
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0