LoginSignup
8
10

More than 5 years have passed since last update.

Movable Typeで記事データをJSONで吐き出すメモ

Posted at

Movable Typeで記事データをJSONで吐き出すメモ

Mobale Type6では、DataAPIなど色々できることが増えているのですが、下位のバージョンでは、そもそも機能がない等出来ない時の対処方法としてメモしておきます。

右カラム・関連記事には使えそうなので覚えておこうと思います。

JSONデータサンプル

index.json
var data = [
<mt:Entries>{
  "title": "<$mt:EntryTitle$>",
  "category": "<mt:IfArchiveTypeEnabled archive_type="Category"><mt:If tag="EntryPrimaryCategory"><mt:EntryPrimaryCategory><$mt:CategoryLabel$></mt:EntryPrimaryCategory></mt:If></mt:IfArchiveTypeEnabled>",
  "date": "<$mt:EntryDate format="%Y-%m-%d"$>"
}<MTIf name="__last__"><MTElse>,</MTElse></MTIf>
</mt:Entries>
]

インデックステンプレート

テスト用に用意したインデックス・スクリプトになります。

index.html
<!DOCTYPE html>
<html lang="ja">
<head>
    <meta charset="UTF-8">
    <title>MT</title>
<script src="http://code.jquery.com/jquery-1.11.1.js"></script>
</head>
<body>
<script type="text/javascript">
$(document).ready(function () {
    // 出力されたJSONのパスを入れる
    $.getJSON("index.json", function(data){
        for(var i in data){
        $("#output").append("<li><strong>" + data[i].title + "</strong></li>");
        }
    });
});
</script>
<ul id="output"></ul>
</body>
</html>
8
10
1

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
8
10