{"id":22503474,"url":"https://github.com/burnworks/movabletype_json_comma_plugin","last_synced_at":"2025-07-18T06:36:35.398Z","repository":{"id":265656782,"uuid":"896405707","full_name":"burnworks/movabletype_json_comma_plugin","owner":"burnworks","description":"Add `mt:JSONComma` function tag for Movable Type","archived":false,"fork":false,"pushed_at":"2024-12-03T12:46:05.000Z","size":9,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-06-27T08:42:10.375Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Perl","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/burnworks.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-11-30T09:22:04.000Z","updated_at":"2024-12-03T12:44:31.000Z","dependencies_parsed_at":"2025-06-27T08:34:11.492Z","dependency_job_id":"32172336-de72-44f9-8c91-099fe737a175","html_url":"https://github.com/burnworks/movabletype_json_comma_plugin","commit_stats":null,"previous_names":["burnworks/movabletype_json_comma_plugin"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/burnworks/movabletype_json_comma_plugin","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/burnworks%2Fmovabletype_json_comma_plugin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/burnworks%2Fmovabletype_json_comma_plugin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/burnworks%2Fmovabletype_json_comma_plugin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/burnworks%2Fmovabletype_json_comma_plugin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/burnworks","download_url":"https://codeload.github.com/burnworks/movabletype_json_comma_plugin/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/burnworks%2Fmovabletype_json_comma_plugin/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":265711239,"owners_count":23815496,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-06T23:32:59.311Z","updated_at":"2025-07-18T06:36:35.373Z","avatar_url":"https://github.com/burnworks.png","language":"Perl","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Movable Type JSON Comma plugin\n\nAdd `mt:JSONComma` function tag for Movable Type.\n\nJSON データをテンプレートで作るときに、面倒くさいカンマ（`,`）の処理（いわゆる「末尾のカンマ」問題）をほんのちょっとだけ楽にする Movable Type プラグイン。\n\n## インストール\n下記のような配置になるように、`JsonComma` ディレクトリ以下を Movable Type のインストールディレクトリに設置してください。\n\n```\n$MT_DIR/\n └ plugins/\n    └ JsonComma/\n       ├ config.yaml\n       └ lib/\n          └ MT/\n            └ Plugin/\n              └ JsonComma.pm\n```\n\n## 追加されるファンクションタグ\n\n```\n\u003c$mt:JsonComma$\u003e\n```\n\n## 使い方\n\n例えば、`\u003cmt:Entries\u003e` や `\u003cmt:Categories\u003e`、`\u003cmt:Pages\u003e` などのブロックタグで JSON を作るとき、下記のようにループの最後だけカンマが出力されないようにする必要があります。\n\n```json\n\u003cmt:Entries\u003e\n  {\n    \"title\": \"\u003c$mt:EntryTitle encode_json=\"1\"$\u003e\",\n    \"author\": \"\u003c$mt:EntryAuthor encode_json=\"1\"$\u003e\"\n  }\u003cmt:Unless name=\"__last__\"\u003e,\u003c/mt:Unless\u003e\n\u003c/mt:Entries\u003e\n```\n\n`\u003c$mt:JsonComma$\u003e` ファンクションタグを使用することで下記のように書けます。\n\n```json\n\u003cmt:Entries\u003e\n  {\n    \"title\": \"\u003c$mt:EntryTitle encode_json=\"1\"$\u003e\",\n    \"author\": \"\u003c$mt:EntryAuthor encode_json=\"1\"$\u003e\"\n  }\u003c$mt:JsonComma$\u003e\n\u003c/mt:Entries\u003e\n```\n\nまた、`\u003cmt:TopLevelCategories\u003e` （`\u003cmt:SubCategories top=\"1\"\u003e` も同じ）に関しては、`__last__` などの予約変数が取得できない（なんで？）ため、下記のように `\u003cmt:SubCatIsLast\u003e` タグなどを使う必要があります。\n\n```json\n\u003cmt:TopLevelCategories\u003e\n\u003cmt:SetVar name=\"comma\" value=\",\"\u003e\n\u003cmt:SubCatIsLast\u003e\u003cmt:SetVar name=\"comma\" value=\"\"\u003e\u003c/mt:SubCatIsLast\u003e\n  {\n    \"label\": \"\u003c$mt:CategoryLabel encode_json=\"1\"$\u003e\",\n    \"path\": \"\u003c$mt:CategoryBasename encode_json=\"1\"$\u003e\",\n    \"link\": \"\u003c$mt:CategoryArchiveLink encode_json=\"1\"$\u003e\"\n  }\u003c$mt:Var name=\"comma\"$\u003e\n\u003c/mt:TopLevelCategories\u003e\n```\n\n`\u003c$mt:JsonComma$\u003e` ファンクションタグを使用することで下記のようにシンプルに書けます。\n\n```json\n\u003cmt:TopLevelCategories\u003e\n  {\n    \"label\": \"\u003c$mt:CategoryLabel encode_json=\"1\"$\u003e\",\n    \"path\": \"\u003c$mt:CategoryBasename encode_json=\"1\"$\u003e\",\n    \"link\": \"\u003c$mt:CategoryArchiveLink encode_json=\"1\"$\u003e\"\n  }\u003c$mt:JsonComma$\u003e\n\u003c/mt:TopLevelCategories\u003e\n```\n\n下記のように、`\u003cmt:TopLevelCategories\u003e` （`\u003cmt:SubCategories top=\"1\"\u003e` も同じ）内で、`\u003cmt:Entries\u003e` をネストして使用した場合でも `\u003c$mt:JsonComma$\u003e` ファンクションタグが動作するようにはしています。\n\n```json\n\u003cmt:SubCategories top=\"1\"\u003e\n  {\n    \"label\": \"\u003c$mt:CategoryLabel encode_json=\"1\"$\u003e\",\n    \"path\": \"\u003c$mt:CategoryBasename encode_json=\"1\"$\u003e\",\n    \"link\": \"\u003c$mt:CategoryArchiveLink encode_json=\"1\"$\u003e\",\n    \"entry\": [\n    \u003cmt:Entries lastn=\"0\"\u003e\n      {\n        \"title\": \"\u003c$mt:EntryTitle encode_json=\"1\"$\u003e\",\n        \"author\": \"\u003c$mt:EntryAuthor encode_json=\"1\"$\u003e\"\n      }\u003c$mt:JsonComma$\u003e\n    \u003c/mt:Entries\u003e\n    ]\n  }\u003c$mt:JsonComma$\u003e\n\u003c/mt:SubCategories\u003e\n```\n\n## 注意点\n\n`\u003cmt:Entries\u003e` と `\u003cmt:EntryCategories\u003e` を下記のようにネストしているときに、ネストされた `\u003cmt:EntryCategories\u003e` 内で `\u003c$mt:JsonComma$\u003e` を使うとうまく行かない（`\u003cmt:Entries\u003e` の最後のループ内は、`\u003cmt:EntryCategories\u003e` 内にカンマが全く出力されない）です。\n\n原因はわかってるんですが、直すの面倒くさいのと、下記の例の様に `glue=\",\"` を使用すれば解決するので、もしうまく行かなかった場合は参考にしてください。\n\n```json\n\u003cmt:Entries\u003e\n  {\n    \"title\": \"\u003c$mt:EntryTitle encode_json=\"1\"$\u003e\",\n    \"author\": \"\u003c$mt:EntryAuthor encode_json=\"1\"$\u003e\",\n    \"category\": [\n      \u003cmt:EntryCategories glue=\",\"\u003e\n      {\n        \"label\": \"\u003c$mt:CategoryLabel encode_json=\"1\"$\u003e\",\n        \"path\": \"\u003c$mt:CategoryBasename encode_json=\"1\"$\u003e\",\n        \"link\": \"\u003c$mt:CategoryArchiveLink encode_json=\"1\"$\u003e\"\n      }\n      \u003c/mt:EntryCategories\u003e\n    ]\n  }\u003c$mt:JsonComma$\u003e\n\u003c/mt:Entries\u003e\n```\n\nその他、すべてのブロックタグの入れ子の組み合わせで試していないので、うまくいったりいかなかったりする場合があると思います。そういう時は別の方法を考えてください。\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fburnworks%2Fmovabletype_json_comma_plugin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fburnworks%2Fmovabletype_json_comma_plugin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fburnworks%2Fmovabletype_json_comma_plugin/lists"}