<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>静的化 &#8211; WordPress Memo</title>
	<atom:link href="https://blog.riverforest-wp.info/tag/%E9%9D%99%E7%9A%84%E5%8C%96/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.riverforest-wp.info</link>
	<description>WordPress に関する覚え書き</description>
	<lastBuildDate>Wed, 12 Nov 2025 22:11:50 +0000</lastBuildDate>
	<language>ja</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>

<image>
	<url>https://blog.riverforest-wp.info/wp-content/uploads/2018/05/cropped-icon-256x256-1-32x32.png</url>
	<title>静的化 &#8211; WordPress Memo</title>
	<link>https://blog.riverforest-wp.info</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>プラグインとシェルスクリプトで静的生成サイトの構築</title>
		<link>https://blog.riverforest-wp.info/static-site-generator/</link>
		
		<dc:creator><![CDATA[Katsushi Kawamori]]></dc:creator>
		<pubDate>Sun, 11 May 2025 00:29:42 +0000</pubDate>
				<category><![CDATA[Plugin]]></category>
		<category><![CDATA[サイト構築]]></category>
		<category><![CDATA[シェルスクリプト]]></category>
		<category><![CDATA[プラグイン]]></category>
		<category><![CDATA[静的化]]></category>
		<guid isPermaLink="false">https://blog.riverforest-wp.info/?p=4069</guid>

					<description><![CDATA[はじめに 先日、静的生成サイトを構築するプラグインを出しました。その補完として、そのプラグインを利用したサイト構築のためのシェルスクリプトを掲載します。このプラグインは、WP-CLI でのみ動作します。 このブログは、こ [&#8230;]]]></description>
										<content:encoded><![CDATA[
<h3 class="wp-block-heading">はじめに</h3>



<p>先日、静的生成サイトを構築するプラグインを出しました。その補完として、そのプラグインを利用したサイト構築のためのシェルスクリプトを掲載します。このプラグインは、WP-CLI でのみ動作します。</p>



<div class="pluginstatsview-card-wrap">
	<div>
		<img decoding="async" src="https://ps.w.org/static-site-generator/assets/icon-256x256.png?rev=3260419" alt="Static Site Generator のアイコン" class="pluginstatsview-card-icon" />
		<div class="pluginstatsview-after-icon">
			<div class="pluginstatsview-bold"><a href="https://wordpress.org/plugins/static-site-generator/" class="pluginstatsview-astyle">Static Site Generator</a></div>
			<div class="pluginstatsview-small">静的サイトを生成します。</div>
			<div class="pluginstatsview-small">作者: <a href="https://profiles.wordpress.org/katsushi-kawamori/">Katsushi Kawamori</a></div>
			<div style="clear: both;"></div>
		</div>
	</div>
	<div style="clear: both;"></div>

	<div class="pluginstatsview-small">
		<span class="pluginstatsview-card-left"><a href="https://wordpress.org/plugins/static-site-generator/#reviews" title="0.0(5点満点中)" class="pluginstatsview-astyle">	<span class="pluginstatsview-stars">
					<span class="dashicons dashicons-star-empty"></span><span class="dashicons dashicons-star-empty"></span><span class="dashicons dashicons-star-empty"></span><span class="dashicons dashicons-star-empty"></span><span class="dashicons dashicons-star-empty"></span>
			</span>
	</a>(0)</span>
		<span class="pluginstatsview-card-right">最終更新: 2日 前</span>
	</div>
	<div class="pluginstatsview-small">
		<span class="pluginstatsview-card-left">1,041ダウンロード</span>
		<span class="pluginstatsview-card-right">検証済み: 7.0</span>
	</div>
	<div class="pluginstatsview-small">
		<span class="pluginstatsview-card-left">ダウンロード: <a href="https://downloads.wordpress.org/plugin/static-site-generator.2.04.zip" class="dashicons dashicons-download pluginstatsview-download"></a></span>
		<span class="pluginstatsview-card-right">リリース: 2025-03-23</span>
	</div>
	<div class="pluginstatsview-small pluginstatsview-card-center">
		2026-03-31 09:30 時点の統計	</div>
</div>



<p>このブログは、このプラグインとシェルスクリプトで静的サイトになっており、WordPress の本体、データベースは取り除かれていて、この記事もテスト環境側の WordPress で書かれています。静的サイトだと、ブログのコメントが出来なくなりますが、ブログのコメントは、SNS 上で記事をシェアした際に、SNS 上で付くコメントの方が多いので、必要を感じません。また、コンタクトフォームは自前のものを、php で用意し、記事中に、<code class="language-php language-html">iframe</code> タグで埋め込みました。</p>



<h3 class="wp-block-heading">要件</h3>



<ol class="wp-block-list">
<li>ローカル開発者環境で、WP-CLI がインストールされており、コマンドプロンプトでシェルスクリプト（#!/bin/sh）が使える事。</li>



<li>ローカル開発者環境と、リモートステージング環境が、SSH で繋がっている事（rsync コマンド利用の為）。</li>



<li>パーマリンクの URL の設定が、トレイリングスラッシュである事。このプラグインは、URL の末尾にパラメータが付いていたり、トレイリングスラッシュが無いと動作を辞め生成しません。</li>



<li>このプラグインはトレイリングスラッシュ以下に、ファイルを生成します。そのファイルを以下に記します。
<ul class="wp-block-list">
<li><code class="language-php language-html">index.html</code> &#8211; html のファイルです。</li>



<li><code class="language-php language-html">index.xml</code> &#8211; フィードのファイルです。</li>



<li><code class="language-php language-html">.htaccess</code> &#8211; <code class="language-php language-html">index.xml</code> と同じ場所に生成します。<code class="language-php language-html">index.xml</code> を認識させるために、<code class="language-php language-html">DirectoryIndex index.xml</code> とだけ書いてあります。Apache2 サーバーのみ使用可能なので、nginx などの他のサーバーの場合は、<code class="language-php language-html">index.xml</code> が認識するように対処してください。</li>
</ul>
</li>



<li>リダイレクトがある場合には、生成しません。ただし、そのディレクトリは作成します。</li>
</ol>



<p class="has-text-align-left">※2 はあると便利ですが、ない場合には、FTP でのアップロードで代替えできます。</p>



<h3 class="wp-block-heading">コード</h3>



<pre class="prism line-numbers"><code class="language-php language-html">#!/bin/sh

# 引数の確認
if &#91; $# -lt 1 ]; then
	echo "使い方: $0 &#91;test|stage]"
	exit 1
fi

# 引数で環境を受け取る
env="$1"

# test WordPress サイト名
wp_site_name="blog.riverforest-wp.info"

# stage サイトディレクトリ名
stage_site_dir="dodesyo:~/public_html/blog.riverforest-wp.info/"

# 環境に応じた静的サイト名と出力ディレクトリを設定
case "$env" in
	test)
		static_site_name="static.riverforest.test"
		abs_path="/home/katsushi/www/$static_site_name"
		;;
	stage)
		static_site_name="blog.riverforest-wp.info"
		abs_path="/home/katsushi/static-temp/$static_site_name"
		;;
	*)
		echo "不正な環境指定です。test、または stage を指定してください。"
		exit 1
		;;
esac

# 静的サイト名のディレクトリを存在確認し、無ければ作成
if &#91; ! -d "$abs_path" ]; then
	mkdir "$abs_path"
	echo "ディレクトリが無いので作成しました: $abs_path"
fi

# Static Site Generator による生成
wp static "$abs_path" https://$static_site_name --cb1="$wp_site_name" --ca1="$static_site_name"

# Static Site Generator による image &amp; video sitemap のみの生成 
wp static "$abs_path" https://$static_site_name --cb1="$wp_site_name" --ca1="$static_site_name" --s --file1="feed/googleimagesitemap/index.xml" --orgurl1="https://$wp_site_name/feed/googleimagesitemap" --file2="feed/googlevideossitemap/index.xml" --orgurl2="https://$wp_site_name/feed/googlevideossitemap"

# 必要ファイル類のコピー wp-includes 関連
cp -f wp-includes/js/wp-emoji-release.min.js "$abs_path"/wp-includes/js
if &#91; ! -d "$abs_path"/wp-includes/images ]; then
	mkdir "$abs_path"/wp-includes/images
fi
cp -rf wp-includes/images/media "$abs_path"/wp-includes/images

# 必要ファイル類のコピー インストールプラグイン関連
cp -rf wp-content/plugins/cookie-law-info/lite/frontend/images "$abs_path"/wp-content/plugins/cookie-law-info/lite/frontend/images
cp -rf wp-content/plugins/riverforest-function/icomoon/fonts "$abs_path"/wp-content/plugins/riverforest-function/icomoon/fonts
if &#91; ! -d "$abs_path"/wp-content/plugins/media-sitemap ]; then
	mkdir "$abs_path"/wp-content/plugins/media-sitemap
fi
cp -rf wp-content/plugins/media-sitemap/xsl "$abs_path"/wp-content/plugins/media-sitemap/xsl

# 必要ファイル類のコピー カスタム php スクリプト（コンタクトフォーム）関連
cp -rf custom "$abs_path"

# xmlrpc.php の削除
rm -f xmlrpc.php

if &#91; "$env" = "stage" ]; then
	echo "ホスト側と rsync で同期を開始します"
	rsync -avz -e ssh "$abs_path"/ "$stage_site_dir"
	echo "ホスト側と rsync で同期を終了しました"
	# ローカルホストの静的ファイルをディレクトリごと全て削除
	rm -rf $abs_path
fi

exit
</code></pre>



<h3 class="wp-block-heading">使い方＆解説</h3>



<p>シェルスクリプト名が、<code class="language-php language-html">static.sh</code> だとして、引数を指定します。引数は <code class="language-php language-html">test</code> か、<code class="language-php language-html">stage</code> のどちらかです。</p>



<ul class="wp-block-list">
<li>引数 <code class="language-php language-html">test</code>  ：ローカル環境にファイルを作成</li>



<li>引数 <code class="language-php language-html">stage</code> ：ローカル環境に一時的にファイルを作成し、リモートステージング環境にファイルをコピー。</li>
</ul>



<h4 class="wp-block-heading">動作</h4>



<figure data-wp-context="{&quot;imageId&quot;:&quot;69cc636fafbe1&quot;}" data-wp-interactive="core/image" data-wp-key="69cc636fafbe1" class="wp-block-image size-large wp-lightbox-container"><img fetchpriority="high" loading="eager" decoding="async" width="1024" height="542" data-wp-class--hide="state.isContentHidden" data-wp-class--show="state.isContentVisible" data-wp-init="callbacks.setButtonStyles" data-wp-on--click="actions.showLightbox" data-wp-on--load="callbacks.setButtonStyles" data-wp-on-window--resize="callbacks.setButtonStyles" src="https://blog.riverforest-wp.info/wp-content/uploads/20250511/terminal-1024x542.png" alt="" class="wp-image-4108" srcset="https://blog.riverforest-wp.info/wp-content/uploads/20250511/terminal-1024x542.png 1024w, https://blog.riverforest-wp.info/wp-content/uploads/20250511/terminal-300x159.png 300w, https://blog.riverforest-wp.info/wp-content/uploads/20250511/terminal-768x406.png 768w, https://blog.riverforest-wp.info/wp-content/uploads/20250511/terminal.png 1200w" sizes="(max-width: 1024px) 100vw, 1024px" /><button
			class="lightbox-trigger"
			type="button"
			aria-haspopup="dialog"
			aria-label="拡大する"
			data-wp-init="callbacks.initTriggerButton"
			data-wp-on--click="actions.showLightbox"
			data-wp-style--right="state.imageButtonRight"
			data-wp-style--top="state.imageButtonTop"
		>
			<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" fill="none" viewBox="0 0 12 12">
				<path fill="#fff" d="M2 0a2 2 0 0 0-2 2v2h1.5V2a.5.5 0 0 1 .5-.5h2V0H2Zm2 10.5H2a.5.5 0 0 1-.5-.5V8H0v2a2 2 0 0 0 2 2h2v-1.5ZM8 12v-1.5h2a.5.5 0 0 0 .5-.5V8H12v2a2 2 0 0 1-2 2H8Zm2-12a2 2 0 0 1 2 2v2h-1.5V2a.5.5 0 0 0-.5-.5H8V0h2Z" />
			</svg>
		</button></figure>



<h4 class="wp-block-heading">解説</h4>



<ul class="wp-block-list">
<li>１３行：テスト環境の WordPress のサイト名。</li>



<li>１６行：ステージング環境の WordPress のディレクトリ名、正確には、<code class="language-php language-html">.ssh</code> の、<code class="language-php language-html">config</code> ファイルに書いた、host 名(<code class="language-php language-html">dodesyo:</code>)とディレクトリ名(<code class="language-php language-html">~/public_html/blog.riverforest-wp.info/</code>)になります。</li>



<li>２１行ー２２行：テスト環境のサイト名と、サイトディレクトリ名。</li>



<li>２５行ー２６行：ステージング環境のサイト名と、サイトディレクトリ名。</li>



<li>４１行：プラグインのコマンド。<code class="language-php language-html"> --cb1</code> オプションは、変更する前（テスト環境）のサイト名、<code class="language-php language-html">--ca1</code> オプションは、変更後（静的サイト）のサイト名。</li>



<li>４４行：プラグインのコマンド。 <code class="language-php language-html">--s</code> オプションは、<code class="language-php language-html">--file</code> <code class="language-php language-html">--orgurl</code> オプションの作業だけ行うの意味。<a href="https://ja.wordpress.org/plugins/media-sitemap/" target="_blank" rel="noreferrer noopener">Media Sitemap for Google</a> というプラグインの生成するサイトマップを生成するためのもの。</li>



<li>４７行ー５１行：WordPress の本体のファイルが必要な場合にコピー。</li>



<li>５４行：<a href="https://ja.wordpress.org/plugins/cookie-law-info/" target="_blank" rel="noreferrer noopener">CookieYes</a> というプラグインで必要なものをコピー。</li>



<li>５５行：このサイトで必要な処理を自身でプラグイン化したもので必要なものをコピー。</li>



<li>５６行ー５９行：<a href="https://ja.wordpress.org/plugins/media-sitemap/" target="_blank" rel="noreferrer noopener">Media Sitemap for Google</a> というプラグインで必要なものをコピー。</li>



<li>６２行：自身で php で作成した、コンタクトフォーム一式をコピー。</li>



<li>６５行：プラグインが、<code class="language-php language-html">xmlrpc.php</code> をコピーしてきてしまうので、削除。</li>



<li>６７行以降：rsync で、ステージング環境に出力するためのもの。FTP 等でコピーするなら不要。</li>
</ul>



<h3 class="wp-block-heading">この方法で静的化したサイト</h3>



<p>以下に、この方法で静的化したこのサイト以外の自分のサイトを示します。</p>



<div class="wp-block-columns is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex">
<div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow">
<style>
.simpleblogcard_img_blockfbd0ca106a2ecef825270c8d283b75fa {
  float: right;
  padding: 10px;
}
.simpleblogcard_borderfbd0ca106a2ecef825270c8d283b75fa {
  border-left: solid 8px #cd162c;
  padding: 0.25em 0.25em;
  background: transparent;
}
.simpleblogcard_titlefbd0ca106a2ecef825270c8d283b75fa {
  line-height: 155%;
  font-weight: bold;
  display: block;
}
.simpleblogcard_descriptionfbd0ca106a2ecef825270c8d283b75fa {
  line-height: 155%;
  color: #333;
}
</style>
<div class="simpleblogcard_wrap">
			<a style="text-decoration: none;" href=https://fbm.riverforest-wp.info/ja/fixed-bottom-menu-%e3%83%a9%e3%82%a4%e3%83%96/ target="_blank" rel="noopener">
			<div class="simpleblogcard_inner">
		<div class="simpleblogcard_borderfbd0ca106a2ecef825270c8d283b75fa">
			fbm.riverforest-wp.info			<div class="simpleblogcard_titlefbd0ca106a2ecef825270c8d283b75fa">
				Fixed Bottom Menu ライブ – WordPress Plugin Fixed Bottom Menu Live Site			</div>
							<div class="simpleblogcard_descriptionfbd0ca106a2ecef825270c8d283b75fa">
					当サイトでは、プラグイン「Fixed Bottom Menu」のフィルターによるカスタマイズ例を紹介しています。「Twenty Twenty-Four」テーマを使用しています。 こ&#8230;				</div>
					</div>
	</div>
	<div style="clear: both;"></div>
	</a>
</div>
</div>



<div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow">
<style>
.simpleblogcard_img_block011a852cdf111418a0a8a6e4214e848e {
  float: right;
  padding: 10px;
}
.simpleblogcard_border011a852cdf111418a0a8a6e4214e848e {
  border-left: solid 8px #cd162c;
  padding: 0.25em 0.25em;
  background: transparent;
}
.simpleblogcard_title011a852cdf111418a0a8a6e4214e848e {
  line-height: 155%;
  font-weight: bold;
  display: block;
}
.simpleblogcard_description011a852cdf111418a0a8a6e4214e848e {
  line-height: 155%;
  color: #333;
}
</style>
<div class="simpleblogcard_wrap">
			<a style="text-decoration: none;" href=https://riverforest-wp.info/ja/plugins-ja/ target="_blank" rel="noopener">
			<div class="simpleblogcard_inner">
		<div class="simpleblogcard_border011a852cdf111418a0a8a6e4214e848e">
			riverforest-wp.info			<div class="simpleblogcard_title011a852cdf111418a0a8a6e4214e848e">
				Riverforest Plugins – Introducing of WordPress plugins made by Katsushi Kawamori. And sales of add-ons.			</div>
							<div class="simpleblogcard_description011a852cdf111418a0a8a6e4214e848e">
					私は以下のプラグインを作成し、WordPress に貢献しています。				</div>
					</div>
	</div>
	<div style="clear: both;"></div>
	</a>
</div>
</div>
</div>



<div class="wp-block-columns is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex">
<div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow">
<style>
.simpleblogcard_img_block90b64b5abff391aaa6bb63819216d694 {
  float: right;
  padding: 10px;
}
.simpleblogcard_border90b64b5abff391aaa6bb63819216d694 {
  border-left: solid 8px #cd162c;
  padding: 0.25em 0.25em;
  background: transparent;
}
.simpleblogcard_title90b64b5abff391aaa6bb63819216d694 {
  line-height: 155%;
  font-weight: bold;
  display: block;
}
.simpleblogcard_description90b64b5abff391aaa6bb63819216d694 {
  line-height: 155%;
  color: #333;
}
</style>
<div class="simpleblogcard_wrap">
			<a style="text-decoration: none;" href=https://compe-scoring.com/ja/compe-scoring-ja/ target="_blank" rel="noopener">
			<div class="simpleblogcard_inner">
		<div class="simpleblogcard_border90b64b5abff391aaa6bb63819216d694">
			compe-scoring.com			<div class="simpleblogcard_title90b64b5abff391aaa6bb63819216d694">
				Competition Scoring System – Competition Scoring System			</div>
							<div class="simpleblogcard_description90b64b5abff391aaa6bb63819216d694">
					このサービスの特徴 このサービスは、競技会・コンクール・コンテストの採点システムです。 競技の初めから終わりまで、自動収集します。PCの前にいる必要はありません。競技が終わった後に&#8230;				</div>
					</div>
	</div>
	<div style="clear: both;"></div>
	</a>
</div>
</div>



<div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow">
<style>
.simpleblogcard_img_block94c060ce0be3d69807c9164036b2d294 {
  float: right;
  padding: 10px;
}
.simpleblogcard_border94c060ce0be3d69807c9164036b2d294 {
  border-left: solid 8px #cd162c;
  padding: 0.25em 0.25em;
  background: transparent;
}
.simpleblogcard_title94c060ce0be3d69807c9164036b2d294 {
  line-height: 155%;
  font-weight: bold;
  display: block;
}
.simpleblogcard_description94c060ce0be3d69807c9164036b2d294 {
  line-height: 155%;
  color: #333;
}
</style>
<div class="simpleblogcard_wrap">
			<a style="text-decoration: none;" href=https://bdc-scoring.com/ja/ballroom-dance-competition-scoring-system-ja/ target="_blank" rel="noopener">
			<div class="simpleblogcard_inner">
		<div class="simpleblogcard_border94c060ce0be3d69807c9164036b2d294">
			bdc-scoring.com			<div class="simpleblogcard_title94c060ce0be3d69807c9164036b2d294">
				Ballroom dance competition Scoring System			</div>
							<div class="simpleblogcard_description94c060ce0be3d69807c9164036b2d294">
					このサービスの特徴 このサービスは、ボールルームダンス競技会の採点システムです。兄弟版サービスの競技会採点システムは以下からお入りください。 競技会採点システム ここで記されるボー&#8230;				</div>
					</div>
	</div>
	<div style="clear: both;"></div>
	</a>
</div>
</div>
</div>



<div class="wp-block-columns is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex">
<div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow">
<style>
.simpleblogcard_img_block93f6d7354f8e57347812edb7ea1a2d3e {
  float: right;
  padding: 10px;
}
.simpleblogcard_border93f6d7354f8e57347812edb7ea1a2d3e {
  border-left: solid 8px #cd162c;
  padding: 0.25em 0.25em;
  background: transparent;
}
.simpleblogcard_title93f6d7354f8e57347812edb7ea1a2d3e {
  line-height: 155%;
  font-weight: bold;
  display: block;
}
.simpleblogcard_description93f6d7354f8e57347812edb7ea1a2d3e {
  line-height: 155%;
  color: #333;
}
</style>
<div class="simpleblogcard_wrap">
			<a style="text-decoration: none;" href=https://pt-syncer.riverforest-wp.info/>
				<figure class="simpleblogcard_img_block93f6d7354f8e57347812edb7ea1a2d3e">
			<img decoding="async" style="border-radius: 5px; width: 100px; height: 100px;" src="https://pt-syncer.riverforest-wp.info/wp-content/uploads/2025/10/icon-300x300.png" alt="PT-Syncer – パーソナルトレーニング向け管理アプリ。QRでチケット管理、Googleカレンダーで予定確認。" />
		</figure>
		<div class="simpleblogcard_inner">
		<div class="simpleblogcard_border93f6d7354f8e57347812edb7ea1a2d3e">
			pt-syncer.riverforest-wp.info			<div class="simpleblogcard_title93f6d7354f8e57347812edb7ea1a2d3e">
				PT-Syncer – パーソナルトレーニング向け管理アプリ。QRでチケット管理、Googleカレンダーで予定確認。			</div>
							<div class="simpleblogcard_description93f6d7354f8e57347812edb7ea1a2d3e">
					PT-Syncer / PT-Syncer Mini ** PT-Syncer（Personal Training Sync）** パーソナルトレーニングや個人レッスン向けのチケッ&#8230;				</div>
					</div>
	</div>
	<div style="clear: both;"></div>
	</a>
</div>
</div>



<div class="wp-block-column is-layout-flow wp-block-column-is-layout-flow"></div>
</div>



<h3 class="wp-block-heading">終わりに</h3>



<p>静的サイトにしてみて、表示が早くなったのを実感します。また、セキュリティ的な圧力から解放されます。</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
