LoginSignup
3
4

More than 5 years have passed since last update.

Simple StaticプラグインでWordPressを静的ページに変換する

Last updated at Posted at 2018-09-16

静的ページ化プラグインで有名なのは

  • Simply Static
    • 一番インストール数やレビュー数が多い。更新もまめにされている。
  • WP Static Site Generator
    • 2番目
  • StaticPress
    • インストールやレビュー数はあまり多くない。あまり更新されていない。
    • 日本人が開発しているっぽい

今回はSimply Staticを使ってみた。
生成はデフォルト設定のままで正常にできたものの、生成されたファイル名・ディレクトリ名が%e3%81%8b%e3%82%8f%e3%81%9b/index.htmlのようになっていて困った。かわせ/index.htmlになっていてくれないと、Apacheで正常に配信できない。
なのでこれを変換するスクリプトをRubyで書いた。

convert.rb
require "cgi"
require "fileutils"

# dir以下を再帰的に変換する
def convert(dir)
  Dir.chdir(dir) do
    Dir.glob("*").each do |filename|
      if filename.include?("%")
        newname = CGI.unescape(filename)
        puts "#{filename} -> #{newname}"
        FileUtils.mv(filename, newname)
      end
    end
    Dir.glob("*").each do |filename|
      if File.directory?(filename)
        convert(filename)
      end
    end
  end
end

convert(".")

使い方は、生成された静的ファイルのトップディレクトリにて

$ ruby convert.rb

これで再帰的に全ファイル名が変換され、そのままApacheで配信できるようになる。

3
4
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
3
4