-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #259 from bearsunday/1page
全てのマニュアルをマージしたページをCIでビルド
- Loading branch information
Showing
6 changed files
with
78 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
name: Run merge_md_files | ||
|
||
on: | ||
pull_request: | ||
workflow_dispatch: | ||
push: | ||
branches: | ||
- master | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
|
||
- name: Set up Ruby | ||
uses: ruby/setup-ruby@v1 | ||
with: | ||
ruby-version: 2.6 | ||
|
||
- name: Run merge_md_files | ||
run: ruby bin/merge_md_files.rb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,5 @@ _site/ | |
.idea | ||
watch | ||
.DS_Store | ||
/manuals/1.0/en/1page.md | ||
/manuals/1.0/ja/1page.md |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
require 'fileutils' | ||
|
||
def generate_combined_file(language, intro_message) | ||
# マークダウンファイルが存在するフォルダ | ||
source_folder = File.expand_path("../manuals/1.0/#{language}/", __dir__) | ||
# 結合されたファイルの出力先 | ||
output_file = "manuals/1.0/#{language}/1page.md" | ||
|
||
puts "Does the source folder exist? #{Dir.exist?(source_folder)}" | ||
raise "Source folder does not exist!" unless File.directory?(source_folder) | ||
|
||
# ファイルを開く | ||
File.open(output_file, "w") do |combined_file| | ||
|
||
# 全体のヘッダーを書き込む | ||
combined_file.write("---\nlayout: docs-#{language}\ntitle: 1 Page Manual\ncategory: Manual\npermalink: /manuals/1.0/#{language}/1page.html\n---\n") | ||
|
||
# 追加のメッセージを書き込む | ||
combined_file.write(intro_message + "\n\n") | ||
|
||
# 指定フォルダ内のすべての.mdファイルを取得し、ソートする | ||
files = Dir.glob(File.join(source_folder, "*.md")).sort | ||
|
||
# 各ファイルを処理する - ヘッダーを削除 | ||
files.each do |filepath| | ||
File.open(filepath, "r") do |file| | ||
# ファイル内容を読む | ||
content = file.read | ||
|
||
# ヘッダー部分を削除 ("---"で囲まれた部分を削除) | ||
content.gsub!(/---.*?---/m, '') | ||
|
||
# 出力ファイルに書き込み | ||
combined_file.write(content + "\n") | ||
end | ||
end | ||
|
||
end | ||
|
||
puts "Markdown files have been combined into #{output_file}" | ||
end | ||
|
||
# 以下の行を使用して関数を2言語で呼び出す | ||
generate_combined_file("ja", "これはBEAR.Sundayの全てのマニュアルを1つに集めたページです。") | ||
generate_combined_file("en", "This is the page that collects all BEAR.Sunday manuals in one place.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters