Skip to content

Instantly share code, notes, and snippets.

@hideki-a
Last active June 7, 2016 05:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hideki-a/87f68bc2bea936fba7697a604681840c to your computer and use it in GitHub Desktop.
Save hideki-a/87f68bc2bea936fba7697a604681840c to your computer and use it in GitHub Desktop.
月別アーカイブへのリンクを年度毎にまとめて出力する(年度は降順・月は昇順)
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<title>年度毎に月別アーカイブへのリンクを出力</title>
</head>
<body>
<mt:ArchiveList type="Monthly">
<$mt:ArchiveTitle regex_replace="/(\d+)年\d+月/","$1" setvar="tmp__current_year"$>
<$mt:ArchiveTitle regex_replace="/\d+年(\d+)月/","$1" setvar="tmp__current_month"$>
<mt:SetVarBlock name="tmp__is_exist"><$mt:ArraySearch name="tmp__year" var="$tmp__current_year"$></mt:SetVarBlock>
<mt:If name="tmp__is_exist" eq="">
<$mt:SetVar name="tmp__year" function="push" value="$tmp__current_year"$>
<mt:If name="tmp__list">
<$mt:SetVar name="tmp__hash" key="$tmp__key" value="$tmp__list"$>
<$mt:SetVar name="tmp__list" value=""$>
</mt:If>
<mt:SetVarBlock name="tmp__key"><$mt:Var name="tmp__current_year"></mt:SetVarBlock>
<mt:ElseIf name="tmp__current_month" lt="4">
<$mt:SetVar name="tmp__current_year" op="--"$>
<mt:SetVarBlock name="tmp__is_exist"><$mt:ArraySearch name="tmp__year" var="$tmp__current_year"$></mt:SetVarBlock>
<mt:Unless name="tmp__is_exist">
<$mt:SetVar name="tmp__year" function="push" value="$tmp__current_year"$>
<mt:If name="tmp__list">
<$mt:SetVar name="tmp__hash" key="$tmp__key" value="$tmp__list"$>
<$mt:SetVar name="tmp__list" value=""$>
</mt:If>
<mt:SetVarBlock name="tmp__key"><$mt:Var name="tmp__current_year"></mt:SetVarBlock>
</mt:Unless>
</mt:If>
<mt:SetVarBlock name="tmp__list" function="push"><li><a href="<$mt:ArchiveLink$>"><$mt:ArchiveTitle regex_replace="/^\d{4}年/",""$></a></li></mt:SetVarBlock>
</mt:ArchiveList>
<mt:If name="tmp__list">
<$mt:SetVar name="tmp__hash" key="$tmp__key" value="$tmp__list"$>
</mt:If>
<mt:Loop name="tmp__year">
<$mt:Var name="tmp__hash{$__value__}" setvar="tmp__output"$>
<$mt:SetVar name="tmp__output_year" value="$__value__"$>
<$mt:ArrayReverse name="tmp__output"$>
<mt:Loop name="tmp__output">
<mt:If name="__first__"><h2><$mt:Var name="tmp__output_year"$>年度</h2><ul></mt:If>
<$mt:Var name="__value__"$>
<mt:If name="__last__"></ul></mt:If>
</mt:Loop>
</mt:Loop>
</body>
</html>
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<title>年度毎に月別アーカイブへのリンクを出力(次月以降は出力しない)</title>
</head>
<body>
<$mt:Date format="%Y%m" setvar="tmp__standard_ym">
<mt:ArchiveList type="Monthly">
<$mt:ArchiveTitle regex_replace="/(\d+)年\d+月/","$1" setvar="tmp__current_year"$>
<$mt:ArchiveTitle regex_replace="/\d+年(\d+)月/","$1" setvar="tmp__current_month"$>
<mt:If name="tmp__current_month" lt="10">
<mt:SetVarBlock name="tmp__current_ym"><$mt:Var name="tmp__current_year"$>0<$mt:Var name="tmp__current_month"$></mt:SetVarBlock>
<mt:Else>
<mt:SetVarBlock name="tmp__current_ym"><$mt:Var name="tmp__current_year"$><$mt:Var name="tmp__current_month"$></mt:SetVarBlock>
</mt:If>
<mt:If name="tmp__current_ym" le="$tmp__standard_ym">
<mt:SetVarBlock name="tmp__is_exist"><$mt:ArraySearch name="tmp__year" var="$tmp__current_year"$></mt:SetVarBlock>
<mt:If name="tmp__is_exist" eq="">
<$mt:SetVar name="tmp__year" function="push" value="$tmp__current_year"$>
<mt:If name="tmp__list">
<$mt:SetVar name="tmp__hash" key="$tmp__key" value="$tmp__list"$>
<$mt:SetVar name="tmp__list" value=""$>
</mt:If>
<mt:SetVarBlock name="tmp__key"><$mt:Var name="tmp__current_year"></mt:SetVarBlock>
<mt:ElseIf name="tmp__current_month" lt="4">
<$mt:SetVar name="tmp__current_year" op="--"$>
<mt:SetVarBlock name="tmp__is_exist"><$mt:ArraySearch name="tmp__year" var="$tmp__current_year"$></mt:SetVarBlock>
<mt:Unless name="tmp__is_exist">
<$mt:SetVar name="tmp__year" function="push" value="$tmp__current_year"$>
<mt:If name="tmp__list">
<$mt:SetVar name="tmp__hash" key="$tmp__key" value="$tmp__list"$>
<$mt:SetVar name="tmp__list" value=""$>
</mt:If>
<mt:SetVarBlock name="tmp__key"><$mt:Var name="tmp__current_year"></mt:SetVarBlock>
</mt:Unless>
</mt:If>
<mt:SetVarBlock name="tmp__list" function="push"><li><a href="<$mt:Var name="tmpl__archive_link"$>"><$mt:ArchiveTitle regex_replace="/^\d{4}年/",""$></a></li></mt:SetVarBlock>
</mt:If>
</mt:ArchiveList>
<mt:If name="tmp__list">
<$mt:SetVar name="tmp__hash" key="$tmp__key" value="$tmp__list"$>
</mt:If>
<mt:Loop name="tmp__year">
<$mt:Var name="tmp__hash{$__value__}" setvar="tmp__output"$>
<$mt:SetVar name="tmp__output_year" value="$__value__"$>
<$mt:ArrayReverse name="tmp__output"$>
<mt:Loop name="tmp__output">
<mt:If name="__first__"><h2><$mt:Var name="tmp__output_year"$>年度</h2><ul></mt:If>
<$mt:Var name="__value__"$>
<mt:If name="__last__"></ul></mt:If>
</mt:Loop>
</mt:Loop>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment