$(function () { // サブメニューの表示/非表示処理 $("ul.sub_menu").slideDown(); $("a.category").click(function () { $("ul.sub_menu").slideUp(); if ($("+ul", this).css("display") == "none") { $("+ul", this).slideDown(); } }); // 2025年のリンクが無ければ追加(付き) if ($('li a').filter(function(){ return $(this).text().replace(/[^\d]/g, '') === '2025'; }).length === 0) { const newListItem = $('
  • 2025年
  • '); const existingListItem = $('li a').filter(function(){ return $(this).text().replace(/[^\d]/g, '') === '2024'; }).parent(); newListItem.insertBefore(existingListItem); } // 2024年のリンク先を変更 $('li a').filter(function(){ return $(this).text().replace(/[^\d]/g, '') === '2024'; }).each(function () { if ($(this).attr('href') === "../biography/index.html") { $(this).attr('href', "../biography/2024.html"); } }); // 2024年のリンクが無ければ追加 if ($('li a').filter(function(){ return $(this).text().replace(/[^\d]/g, '') === '2024'; }).length === 0) { const newListItem = $('
  • 2024年
  • '); const existingListItem = $('li a').filter(function(){ return $(this).text().replace(/[^\d]/g, '') === '2023'; }).parent(); newListItem.insertBefore(existingListItem); } // 2023年のリンク先を変更 $('li a').filter(function(){ return $(this).text().replace(/[^\d]/g, '') === '2023'; }).each(function () { if ($(this).attr('href') === "../biography/index.html") { $(this).attr('href', "../biography/2023.html"); } }); // --- ここからクラスの自動付与 --- // 現在ページの年(例:2021年)を取得 var year = location.pathname.match(/\/biography\/(\d{4})\.html$/); var thisYear; if (year) { thisYear = year[1] + "年"; } else { // index.htmlの場合 thisYear = "2025年"; // 最新年に合わせて } // すべての年リンクから一度class="oth"を消す $('#side_menu .sub_menu li a').removeClass('oth'); // 「今の年」以外の年にclass="oth"をつける(テキストで比較) $('#side_menu .sub_menu li a').each(function () { // テキストで判定(前後空白やuタグ回避) if ($(this).text().trim() !== thisYear) { $(this).addClass('oth'); } }); // 下線()の処理 // 全部一度テキストだけにリセット $('#side_menu .sub_menu li a').each(function () { $(this).html($(this).text()); }); // 「今の年」だけで包む $('#side_menu .sub_menu li a').each(function () { if ($(this).text().trim() === thisYear) { $(this).html('' + $(this).text() + ''); } }); });