Skip to content
Merged

Feature #1633

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@ alias:
tags/Security: categories/Security/
tags/IoT: categories/IoT/
tags/モバイルアプリ: categories/Mobile/ # Mobileカテゴリの新設対応
# カテゴリの変更
categories/Design: tags/UI-UX/

# 名寄せなど
tags/GCP/: tags/GoogleCloud/
tags/画像認識/: tags/画像処理/
Expand Down
122 changes: 122 additions & 0 deletions categorize_mobile_posts.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
import os

# --- 設定 ---
POSTS_DIRECTORY = 'source/_posts'
# 上記リストから、実際に移行したいタグをここに列挙します
TARGET_TAGS = [
'Git'
]
# 上書きする新しいカテゴリ
NEW_CATEGORY = 'DevOps'
# --- 設定ここまで ---

def replace_category_for_mobile_tags(file_path):
"""
ファイルのfront matterをチェックし、ターゲットタグが含まれていれば
カテゴリを'Mobile'に置換する。他の行のフォーマットは保持する。
"""
try:
with open(file_path, 'r', encoding='utf-8') as f:
lines = f.readlines()

# --- ステップ1: まず対象ファイルか判定する ---
in_front_matter = False
in_tags_list = False
has_target_tag = False
for line in lines:
if line.strip() == '---':
if in_front_matter: # front matterの終わり
break
else: # front matterの始まり
in_front_matter = True
continue

if in_front_matter:
stripped_line = line.strip()
if not line.startswith((' ', '\t')):
in_tags_list = stripped_line.startswith(('tag:', 'tags:'))

if in_tags_list and stripped_line.startswith('-'):
tag_value = stripped_line[1:].strip().strip('\'"')
if tag_value in TARGET_TAGS:
has_target_tag = True
break

# ターゲットタグがなければ、何もせず終了
if not has_target_tag:
return False, "対象外"

# --- ステップ2: 対象ファイルだった場合、内容を書き換える ---
new_lines = []
in_front_matter = False
in_category_list = False
was_modified = False

for line in lines:
if line.strip() == '---':
if in_front_matter:
in_front_matter = False
in_category_list = False
else:
in_front_matter = True
new_lines.append(line)
continue

if in_front_matter:
stripped_line = line.strip()

if not line.startswith((' ', '\t')):
# categoryキーを見つけたら、新しい定義に置き換える
if stripped_line.startswith(('category:', 'categories:')):
new_lines.append(f'category:\n - {NEW_CATEGORY}\n')
in_category_list = True
was_modified = True
continue
else:
in_category_list = False

# 古いcategoryリスト内のアイテム行ならスキップ(削除)
if in_category_list and stripped_line.startswith('-'):
was_modified = True
continue

# その他の行はそのまま追加
new_lines.append(line)
else:
new_lines.append(line)

if was_modified:
with open(file_path, 'w', encoding='utf-8') as f:
f.writelines(new_lines)
return True, "カテゴリを'Mobile'に置換しました"
else:
return False, "カテゴリが元々ないため処理スキップ"

except Exception as e:
return False, f"エラー: {e}"

def main():
"""メイン処理"""
if not os.path.isdir(POSTS_DIRECTORY):
print(f"エラー: '{POSTS_DIRECTORY}' が見つかりません。")
return

print(f"カテゴリ置換処理を開始します (対象タグ: {', '.join(TARGET_TAGS)})...")
updated_files_count = 0

for root, _, files in os.walk(POSTS_DIRECTORY):
for file in files:
if file.endswith('.md'):
file_path = os.path.join(root, file)
was_updated, message = replace_category_for_mobile_tags(file_path)
if was_updated:
updated_files_count += 1
print(f"✅ {message}: {file_path}")

if updated_files_count > 0:
print(f"\n完了しました。合計 {updated_files_count} 個のファイルを修正しました。")
else:
print("\n完了しました。修正対象のファイルは見つかりませんでした。")

if __name__ == '__main__':
main()
2 changes: 1 addition & 1 deletion source/_posts/2016/20160721-icons.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ tag:
- UI/UX
- 資料作成
category:
- Design
- Business
thumbnail: /images/2016/20160721/thumbnail_20160721.png
author: 木村優里
lede: "これさえあればシステム構成図がだいたい描けるアイコンセットを公開します!"
Expand Down
2 changes: 1 addition & 1 deletion source/_posts/2019/20190530-GCP資格.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ tag:
- 合格記
- Kubernetes
category:
- Infrastructure
- DevOps
author: 市川諒
lede: "GCP Professional Cloud Architect認定資格を取得するために何をしたか、その結果で何を得たかなど赤裸々に語ります。"
---
Expand Down
2 changes: 1 addition & 1 deletion source/_posts/2019/20190604-trace.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ tag:
- OpenTelemetry
- Telemetry
category:
- Infrastructure
- DevOps
author: 澁川喜規
lede: "「分散トレースとは何か」という話がまとまっていて、初学者に「これ読んどいて」と言えるようなページがなかったので社内向けの資料をベースに技術ブログでも公開します。"
---
Expand Down
Loading
Loading