ブロガーのブログにコピペで簡単にHTMLサイトマップを作る

2024年5月21日火曜日

サイトマップ ブログ

t f B! P L

ブロガーのブログにコピペで簡単にHTMLサイトマップを作る方法

サイトマップ

HTMLサイトマップのコードをコピーして個別ページに貼り付けます。
コントロールパネルからページ新規作成で表示をHTMLにして貼り付けます。
オプションは許可しないで送信。これでサイトマップが読み込まれます。

  1. <div id="bp_toc">読込中...</div>
  2. <script type="text/javascript">
  3. // ---------------------------------------------------
  4. // BLOGTOC
  5. ,
  6. // ---------------------------------------------------
  7. // BlogToc creates a clickable Table Of Contents for
  8. // Blogger Blogs.
  9. // It uses the JSON post feed, and create a ToC of it.
  10. // The ToC can be sorted by title or by date, both
  11. // ascending and descending, and can be filtered by
  12. // label.
  13. // ---------------------------------------------------
  14. // Author: Syed Faizan Ali
  15. // Url: https://www.mybloggerlab.com
  16. // Version: 2
  17. // Date: 2007-04-12
  18. // ---------------------------------------------------
  19. // Japanese Localization by Fujiyan.
  20. // Url: https://fujilogic.blogspot.com/2019/05/sitemap.html
  21. // ---------------------------------------------------
  22. // global arrays
  23.  
  24.    var postTitle = new Array(); // array of posttitles
  25.    var postUrl = new Array(); // array of posturls
  26.    var postDate = new Array(); // array of post publish dates
  27.    var postSum = new Array(); // array of post summaries
  28.    var postLabels = new Array();// array of post labels
  29.  
  30. // global variables
  31.    var sortBy = "datenewest"; // default value for sorting ToC
  32.    var tocLoaded = false; // true if feed is read and ToC can be displayed
  33.    var numChars = 250; // マウスオン時にツールチップ表示する概要文字数
  34.    var postFilter = ''; // デフォルトで表示するラベル名
  35.    var tocdiv = document.getElementById("bp_toc"); //the toc container
  36.    var totalEntires =0; //Entries grabbed till now
  37.    var totalPosts =0; //Total number of posts in the blog.
  38.  
  39. // main callback function
  40.  
  41. function loadtoc(json) {
  42.  
  43.    function getPostData() {
  44.    // this functions reads all postdata from the json-feed and stores it in arrays
  45.       if ("entry" in json.feed) {
  46.          var numEntries = json.feed.entry.length;
  47.          totalEntires = totalEntires + numEntries;
  48.          totalPosts=json.feed.openSearch$totalResults.$t
  49.          if(totalPosts>totalEntires)
  50.          {
  51.          var nextjsoncall = document.createElement('script');
  52.          nextjsoncall.type = 'text/javascript';
  53.          startindex=totalEntires+1;
  54.          nextjsoncall.setAttribute("src", "/feeds/posts/summary?start-index=" + startindex + "&max-results=50&alt=json-in-script&callback=loadtoc");
  55.          tocdiv.appendChild(nextjsoncall);
  56.          }
  57.       // main loop gets all the entries from the feed
  58.          for (var i = 0; i < numEntries; i++) {
  59.          // get the entry from the feed
  60.             var entry = json.feed.entry[i];
  61.  
  62.          // get the posttitle from the entry
  63.             var posttitle = entry.title.$t;
  64.  
  65.          // get the post date from the entry
  66.             var postdate = entry.published.$t.substring(0,10).replace(/-/g,"/");
  67.  
  68.          // get the post url from the entry
  69.             var posturl;
  70.             for (var k = 0; k < entry.link.length; k++) {
  71.                if (entry.link[k].rel == 'alternate') {
  72.                posturl = entry.link[k].href;
  73.                break;
  74.                }
  75.             }
  76.  
  77.          // get the post contents from the entry
  78.          // strip all html-characters, and reduce it to a summary
  79.             if ("content" in entry) {
  80.                var postcontent = entry.content.$t;}
  81.             else
  82.                if ("summary" in entry) {
  83.                   var postcontent = entry.summary.$t;}
  84.                else var postcontent = "";
  85.          // strip off all html-tags
  86.             var re = /<\S[^>]*>/g;
  87.             postcontent = postcontent.replace(re, "");
  88.          // reduce postcontent to numchar characters, and then cut it off at the last whole word
  89.             if (postcontent.length > numChars) {
  90.                postcontent = postcontent.substring(0,numChars);
  91.                var quoteEnd = postcontent.lastIndexOf(" ");
  92.                postcontent = postcontent.substring(0,quoteEnd) + '...';
  93.             }
  94.  
  95.          // get the post labels from the entry
  96.             var pll = '';
  97.             if ("category" in entry) {
  98.                for (var k = 0; k < entry.category.length; k++) {
  99.                   pll += '<a href="javascript:filterPosts(\'' + entry.category[k].term + '\');" title="ラベル 「' + entry.category[k].term + '」 の記事を表示">' + entry.category[k].term + '</a>, ';
  100.                }
  101.             var l = pll.lastIndexOf(',');
  102.             if (l != -1) { pll = pll.substring(0,l); }
  103.             }
  104.  
  105.          // add the post data to the arrays
  106.             postTitle.push(posttitle);
  107.             postDate.push(postdate);
  108.             postUrl.push(posturl);
  109.             postSum.push(postcontent);
  110.             postLabels.push(pll);
  111.          }
  112.       }
  113.       if(totalEntires==totalPosts) {tocLoaded=true;showToc();}
  114.    } // end of getPostData
  115.  
  116. // start of showtoc function body
  117. // get the number of entries that are in the feed
  118. // numEntries = json.feed.entry.length;
  119.  
  120. // get the postdata from the feed
  121.    getPostData();
  122.  
  123. // sort the arrays
  124.    sortPosts(sortBy);
  125.    tocLoaded = true;
  126. }
  127.  
  128.  
  129.  
  130. // filter and sort functions
  131.  
  132.  
  133. function filterPosts(filter) {
  134. // This function changes the filter
  135. // and displays the filtered list of posts
  136.   // document.getElementById("bp_toc").scrollTop = document.getElementById("bp_toc").offsetTop;;
  137.    postFilter = filter;
  138.    displayToc(postFilter);
  139. } // end filterPosts
  140.  
  141. function allPosts() {
  142. // This function resets the filter
  143. // and displays all posts
  144.  
  145.    postFilter = '';
  146.    displayToc(postFilter);
  147. } // end allPosts
  148.  
  149. function sortPosts(sortBy) {
  150. // This function is a simple bubble-sort routine
  151. // that sorts the posts
  152.  
  153.    function swapPosts(x,y) {
  154.    // Swaps 2 ToC-entries by swapping all array-elements
  155.       var temp = postTitle[x];
  156.       postTitle[x] = postTitle[y];
  157.       postTitle[y] = temp;
  158.       var temp = postDate[x];
  159.       postDate[x] = postDate[y];
  160.       postDate[y] = temp;
  161.       var temp = postUrl[x];
  162.       postUrl[x] = postUrl[y];
  163.       postUrl[y] = temp;
  164.       var temp = postSum[x];
  165.       postSum[x] = postSum[y];
  166.       postSum[y] = temp;
  167.       var temp = postLabels[x];
  168.       postLabels[x] = postLabels[y];
  169.       postLabels[y] = temp;
  170.    } // end swapPosts
  171.  
  172.    for (var i=0; i < postTitle.length-1; i++) {
  173.       for (var j=i+1; j<postTitle.length; j++) {
  174.          if (sortBy == "titleasc") { if (postTitle[i] > postTitle[j]) { swapPosts(i,j); } }
  175.          if (sortBy == "titledesc") { if (postTitle[i] < postTitle[j]) { swapPosts(i,j); } }
  176.          if (sortBy == "dateoldest") { if (postDate[i] > postDate[j]) { swapPosts(i,j); } }
  177.          if (sortBy == "datenewest") { if (postDate[i] < postDate[j]) { swapPosts(i,j); } }
  178.       }
  179.    }
  180. } // end sortPosts
  181.  
  182. // displaying the toc
  183.  
  184. function displayToc(filter) {
  185. // this function creates a three-column table and adds it to the screen
  186.    var numDisplayed = 0;
  187.    var tocTable = '';
  188.    var tocHead1 = 'タイトル';
  189.    var tocTool1 = 'タイトル順に並べ替え';
  190.    var tocHead2 = '投稿日';
  191.    var tocTool2 = '投稿日順に並べ替え';
  192.    var tocHead3 = 'ラベルを選択';
  193.    var tocTool3 = '';
  194.    if (sortBy == "titleasc") {
  195.       tocTool1 += ' (降順)';
  196.       tocTool2 += ' (昇順)';
  197.    }
  198.    if (sortBy == "titledesc") {
  199.       tocTool1 += ' (昇順)';
  200.       tocTool2 += ' (昇順)';
  201.    }
  202.    if (sortBy == "dateoldest") {
  203.       tocTool1 += ' (昇順)';
  204.       tocTool2 += ' (昇順)';
  205.    }
  206.    if (sortBy == "datenewest") {
  207.       tocTool1 += ' (昇順)';
  208.       tocTool2 += ' (降順)';
  209.    }
  210.    if (postFilter != '') {
  211.       tocTool3 = '全ての記事を表示する';
  212.    }
  213.    tocTable += '<table>';
  214.    tocTable += '<tr>';
  215.    tocTable += '<td class="toc-header-col1">';
  216.    tocTable += '<a href="javascript:toggleTitleSort();" title="' + tocTool1 + '">' + tocHead1 + '</a>';
  217.    tocTable += '</td>';
  218.    tocTable += '<td class="toc-header-col2">';
  219.    tocTable += '<a href="javascript:toggleDateSort();" title="' + tocTool2 + '">' + tocHead2 + '</a>';
  220.    tocTable += '</td>';
  221.    tocTable += '<td class="toc-header-col3">';
  222.    tocTable += '<span>' + tocHead3 + '</span>';
  223.    tocTable += '</td>';
  224.    tocTable += '</tr>';
  225.    for (var i = 0; i < postTitle.length; i++) {
  226.       if (filter == '') {
  227.          tocTable += '<tr><td class="toc-entry-col1"><a href="' + postUrl[i] + '" title="' + postSum[i] + '">' + postTitle[i] + '</a></td><td class="toc-entry-col2">' + postDate[i] + '</td><td class="toc-entry-col3">' + postLabels[i] + '</td></tr>';
  228.          numDisplayed++;
  229.       } else {
  230.           z = postLabels[i].lastIndexOf(filter);
  231.           if ( z!= -1) {
  232.              tocTable += '<tr><td class="toc-entry-col1"><a href="' + postUrl[i] + '" title="' + postSum[i] + '">' + postTitle[i] + '</a></td><td class="toc-entry-col2">' + postDate[i] + '</td><td class="toc-entry-col3">' + postLabels[i] + '</td></tr>';
  233.              numDisplayed++;
  234.           }
  235.         }
  236.    }
  237.    tocTable += '</table>';
  238.    if (numDisplayed == postTitle.length) {
  239.       var tocNote = '<span class="toc-note">全 ' + postTitle.length + ' 件の記事を表示しています<br/></span>';
  240.    }
  241.    else {
  242.       var tocNote = '<span class="toc-note">全 '+ postTitle.length + ' 件中 ラベル「<b>';
  243.       tocNote += postFilter + '</b>」の ' + numDisplayed + ' 件の記事を表示しています<br/><a href="javascript:allPosts();">' + tocTool3 + '</a></span>';
  244.    }
  245.    tocdiv.innerHTML = tocNote + tocTable;
  246. } // end of displayToc
  247.  
  248. function toggleTitleSort() {
  249.    if (sortBy == "titleasc") { sortBy = "titledesc"; }
  250.    else { sortBy = "titleasc"; }
  251.    sortPosts(sortBy);
  252.    displayToc(postFilter);
  253. } // end toggleTitleSort
  254.  
  255. function toggleDateSort() {
  256.    if (sortBy == "datenewest") { sortBy = "dateoldest"; }
  257.    else { sortBy = "datenewest"; }
  258.    sortPosts(sortBy);
  259.    displayToc(postFilter);
  260. } // end toggleTitleSort
  261.  
  262.  
  263. function showToc() {
  264.   if (tocLoaded) {
  265.      displayToc(postFilter);
  266.      var toclink = document.getElementById("toclink");
  267.  
  268.   }
  269. }
  270.  
  271. </script>
  272. <script src="/feeds/posts/default?alt=json-in-script&amp;max-results=50&amp;callback=loadtoc" type="text/javascript"></script>
  273.  
  274. <style>
  275. #bp_toc {
  276.     margin: 0 auto 2em;
  277.     padding: 0;
  278.     width: 100%;
  279. }
  280. #bp_toc tbody {
  281.     border-bottom: 1px solid #ddd;
  282. }
  283. #bp_toc table {
  284.     width: 100%;
  285.     margin: 0 auto;
  286.     counter-reset: rowNumber;
  287.     border-collapse: collapse;
  288.     border-left: 1px solid #ddd;
  289. }
  290. #bp_toc td:not(.toc-entry-col3),
  291. #bp_toc tr {
  292.   border-right: 1px solid #ddd;
  293. }
  294. .toc-note {
  295.     line-height: 1.5em;
  296.     margin-bottom: 1em;
  297.     display: block;
  298.     text-align: center;
  299. }
  300. .toc-note a {/*全記事表示に戻すリンク*/
  301.  
  302. }
  303. .toc-note a:hover {
  304.  
  305. }
  306. #bp_toc tr:nth-child(2n) {
  307.     background: rgba(0,80,200,.1);/*奇数行の背景色*/
  308. }
  309. .toc-entry-col1 a:hover {
  310.     background: rgba(0,80,200,.2);/*タイトルホバー時の背景色*/
  311.     text-decoration: none!important;
  312. }
  313. #bp_toc table tr:first-child a,
  314. #bp_toc table tr:first-child span {/*ナビゲーション*/
  315.     background: #bbb;
  316.     color: #fff!important;
  317.     font-weight: bold;
  318.     text-align: center;
  319.     padding: 5px 0;
  320.     display: block;
  321.     width: 100%;
  322.     border-top: 1px solid #ddd;
  323. }
  324. #bp_toc table tr:first-child a:hover {
  325.     opacity: .8;
  326.     text-decoration: none;
  327. }
  328. .toc-header-col1 {
  329.     width: 55%;/*タイトル(番号含む)枠の幅*/
  330. }
  331. .toc-header-col2 {
  332.     width: 12%;/*投稿日枠の幅*/
  333. }
  334. .toc-header-col3 {
  335.     width: 33%;/*ラベル枠の幅*/
  336. }
  337. #bp_toc table tr td.toc-entry-col1:first-child::before {
  338.     content: counter(rowNumber);
  339.     width: 2.6em;/*記事番号枠の幅*/
  340.     text-align: center;
  341.     padding: 12px 3px 0;
  342.     border-right: 1px solid #ddd;
  343. }
  344. .toc-entry-col1 {/*記事番号*/
  345.     display: flex;
  346.     counter-increment: rowNumber;
  347.     font-size: 12px;
  348.     line-height: 1.5em;
  349. }
  350. .toc-entry-col1 a {/*タイトル*/
  351.     display: block;
  352.     height: 100%;
  353.     width: 100%;
  354.     font-size: 14px;
  355.     font-weight: bold;
  356.     padding: 10px .5em 10px;
  357.     line-height: 1.3em;
  358.     color: inherit!important;
  359. }
  360. .toc-entry-col2 {/*投稿日*/
  361.     font-size: 13px;
  362.     text-align: center;
  363. }
  364. .toc-entry-col3 {/*ラベル*/
  365.     font-size: 13px;
  366.     padding: 5px;
  367.     line-height: 1.5em;
  368. }
  369. </style>

アドセンス審査に必要なプライバシーポリシーページの作成

アドセンス審査に必要なプライバシーポリシーページの作成

アドセンス審査に必要なプライバシーポリシーページの作成


ブログランキング・にほんブログ村へ

このブログを検索

自己紹介

自分の写真
Bloggerブログのカスタマイズ特訓中です。皆さん宜しくお願いします。

QooQ