我如何从Blogger的javascript网站地图生成器中排除标签?

问题描述 投票:1回答:1

所以我有一个脚本,显示我的博客的网站地图,就像这样。

enter image description here

当它被点击时,显示的是这样的。enter image description here

基本上,我想排除一些标签显示在网站上,并显示第一个标签的文章,当加载时,像第二张图片。

我尝试使用 cat_remove = ['Label12', 'Label13']; 去除标签,但没有成功。

并尝试使用 show_post (cat [0] .term, 1,0); 在加载时显示第一个标签的帖子,但这也不行。

我希望我已经记录了一切。先谢谢你了。

var cat_home = 'https://myblog.blogspot.com';
cat_numb = 4;
cat_pre = '< Anterior';
cat_nex = 'Siguiente >';
var cat_name;
var cat_start;
var cat_class;

function show_post2(a) {
  var tt = a.feed.openSearch$totalResults.$t;
  dw = '';
  dw += '<ul>';
  for (var i = 0; i < cat_numb && i < a.feed.entry.length; i++) {
    var entry = a.feed.entry[i];
    cat_title = entry.title.$t;
    for (var j = 0; j < entry.link.length; j++) {
      if (entry.link[j].rel == 'alternate') {
        var cat_url = entry.link[j].href
      }
    }
    dw += '<li>';
    dw += (cat_start + i) + '. <a href="' + cat_url + '" rel="nofollow" title="' + cat_title + '">' + cat_title + '</a>';
    dw += '</li>'
  }
  dw += '</ul>';
  dw += '<div id="navi-cat">';
  if (cat_start > 1) {
    dw += '<a href="" onclick="show_post(\'' + cat_name + '\',\'' + (cat_start - cat_numb) + '\',\'' + cat_class + '\');return false" title="' + cat_pre + '">' + cat_pre + '</a>'
  }
  if ((cat_start + cat_numb - 1) < tt) {
    dw += '<a href="" onclick="show_post(\'' + cat_name + '\',\'' + (cat_start + cat_numb) + '\',\'' + cat_class + '\');return false" title="' + cat_nex + '">' + cat_nex + '</a>'
  }
  dw += '<span>' + cat_start;
  if (cat_start != tt) {
    dw += ' &ndash; ' + (cat_start + i - 1)
  }
  dw += ' / ' + tt + '</span>';
  dw += '</div>';
  document.getElementById('show-post').innerHTML = dw + '<style type="text/css">.cat-' + cat_class + ' a{background:#bbb!important;color:#fff!important}<\/style>'
}

function show_post(a, b, c) {
  var d = document.getElementsByTagName('head')[0];
  e = document.createElement('script');
  e.type = 'text/javascript';
  e.setAttribute('src', cat_home + '/feeds/posts/default/-/' + a + '?alt=json-in-script&start-index=' + b + '&max-results=' + cat_numb + '&callback=show_post2');
  d.appendChild(e);
  cat_name = a;
  cat_start = parseInt(b), cat_class = c
}

function show_cat(a) {
  var cat = a.feed.category;
  dw = '';
  dw += '<ul>';
  for (var i = 0; i < cat.length - 1; i++) {
    for (var j = i + 1; j < cat.length; j++) {
      if (cat[i].term > cat[j].term) {
        cat_hv = cat[i].term;
        cat[i].term = cat[j].term;
        cat[j].term = cat_hv
      }
    }
  }
  for (var i = 0; i < cat.length; i++) {
    dw += '<li class="cat-' + i + '">';
    dw += '<a href="" onclick="show_post(\'' + cat[i].term + '\',\'1\',\'' + i + '\');return false" title="';
    dw += cat[i].term;
    dw += '">';
    dw += cat[i].term;
    dw += '</a>';
    dw += '</li>'
  }
  dw += '</ul>';
  document.getElementById('show-cat').innerHTML = dw
}
document.write('<script type="text/javascript" src="' + cat_home + '/feeds/posts/default?alt=json-in-script&max-results=0&callback=show_cat"><\/script>');
#show-cat {
  float: left;
  margin-right: 33px;
  width: 165px;
  height: 310px;
  overflow-x: hidden;
  overflow-y: auto;
  line-height: 18px
}

#show-cat ul {
  margin: 0;
  border-top: 0 solid rgba(0, 0, 0, 0.1);
  padding: 0
}

#show-post ul li {
  list-style-type: none;
  margin: 0 0 0 -25px;
  padding: 10px 0;
  border-bottom: 1px solid rgba(0, 0, 0, 0.1)
}

#show-post ul li:hover {
  margin-right: 10px;
  border-color: #fcd3d3
}

#show-cat ul li a {
  display: block;
  padding: 10px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.1);
  transition: initial
}

#navi-cat a:hover {
  color: #fff!important
}

#show-cat ul li:last-child a {
  border-bottom: none
}

#show-cat ul li a,
#navi-cat a {
  background: #fff;
  color: #555;
  font-weight: bold;
  text-decoration: none
}

#show-cat ul li a,
#navi-cat a,
#navi-cat span {
  font-size: 13px
}

#show-cat ul li a:hover,
#navi-cat a:hover {
  background: #666;
  color: #fff
}

#show-post {
  float: left;
  width: 69%;
  line-height: 1.6em
}

#show-post a {
  color: #333;
  font-size: 14px
}

#show-post a:hover {
  color: #f14b4b
}

#navi-cat {
  padding: 20px 0
}

#navi-cat a {
  padding: 5px 10px;
  background: rgba(0, 0, 0, 0.7);
  margin: 0 5px 0 0;
  color: #fff;
  border-radius: 3px;
}

#navi-cat a:nth-child(2) {
  background: #f14b4b;
  margin: 0 10px 0 0;
  color: #fff
}

#navi-cat span {
  float: right;
  padding: 5px 0;
  font-size: 12px;
  color: rgba(0, 0, 0, 0.5);
  font-weight: 700
}

#show-cat::-webkit-scrollbar {
  width: 8px;
  height: 8px
}

#show-cat::-webkit-scrollbar-track {
  background-color: rgba(0, 0, 0, .1);
}

#show-cat::-webkit-scrollbar-thumb:hover {
  background-color: rgba(0, 0, 0, .6)
}

#show-cat::-webkit-scrollbar-thumb {
  background-color: rgba(0, 0, 0, .4);
  transition: all 400ms ease-in-out
}

@media screen and (max-width:768px) {
  #show-cat {
    width: 35%
  }
  #show-post {
    width: 59%
  }
}

@media screen and (max-width:480px) {
  #show-cat {
    width: 100%;
    margin: 20px 0
  }
  #show-post {
    width: 100%
  }
}
<div id='show-cat'></div>
<div id='show-post'>
  <div style='clear:both'></div>
javascript blogger
1个回答
1
投票

这里是如何排除标签

cat = cat.filter(i => !["Label12","Label13"].includes(i.term));

把它放在这个变量之后 var cat = a.feed.category;

要在加载时显示第一个标签的文章,请使用以下方法 show_post(cat[0].term, 1) 排序后,。

var cat_home = 'https://myblog.blogspot.com';
cat_numb = 4;
cat_pre = '< Anterior';
cat_nex = 'Siguiente >';
var cat_name;
var cat_start;
var cat_class;

function show_post2(a) {
  var tt = a.feed.openSearch$totalResults.$t;
  dw = '';
  dw += '<ul>';
  for (var i = 0; i < cat_numb && i < a.feed.entry.length; i++) {
    var entry = a.feed.entry[i];
    cat_title = entry.title.$t;
    for (var j = 0; j < entry.link.length; j++) {
      if (entry.link[j].rel == 'alternate') {
        var cat_url = entry.link[j].href
      }
    }
    dw += '<li>';
    dw += (cat_start + i) + '. <a href="' + cat_url + '" rel="nofollow" title="' + cat_title + '">' + cat_title + '</a>';
    dw += '</li>'
  }
  dw += '</ul>';
  dw += '<div id="navi-cat">';
  if (cat_start > 1) {
    dw += '<a href="" onclick="show_post(\'' + cat_name + '\',\'' + (cat_start - cat_numb) + '\',\'' + cat_class + '\');return false" title="' + cat_pre + '">' + cat_pre + '</a>'
  }
  if ((cat_start + cat_numb - 1) < tt) {
    dw += '<a href="" onclick="show_post(\'' + cat_name + '\',\'' + (cat_start + cat_numb) + '\',\'' + cat_class + '\');return false" title="' + cat_nex + '">' + cat_nex + '</a>'
  }
  dw += '<span>' + cat_start;
  if (cat_start != tt) {
    dw += ' &ndash; ' + (cat_start + i - 1)
  }
  dw += ' / ' + tt + '</span>';
  dw += '</div>';
  document.getElementById('show-post').innerHTML = dw + '<style type="text/css">.cat-' + cat_class + ' a{background:#bbb!important;color:#fff!important}<\/style>'
}

function show_post(a, b, c) {
  var d = document.getElementsByTagName('head')[0];
  e = document.createElement('script');
  e.type = 'text/javascript';
  e.setAttribute('src', cat_home + '/feeds/posts/default/-/' + a + '?alt=json-in-script&start-index=' + b + '&max-results=' + cat_numb + '&callback=show_post2');
  d.appendChild(e);
  cat_name = a;
  cat_start = parseInt(b), cat_class = c
}

function show_cat(a) {
  var cat = a.feed.category;
  cat = cat.filter(i => !["Label12","Label13"].includes(i.term));
  dw = '';
  dw += '<ul>';
  for (var i = 0; i < cat.length - 1; i++) {
    for (var j = i + 1; j < cat.length; j++) {
      if (cat[i].term > cat[j].term) {
        cat_hv = cat[i].term;
        cat[i].term = cat[j].term;
        cat[j].term = cat_hv
      }
    }
  }
  for (var i = 0; i < cat.length; i++) {
    dw += '<li class="cat-' + i + '">';
    dw += '<a href="" onclick="show_post(\'' + cat[i].term + '\',\'1\',\'' + i + '\');return false" title="';
    dw += cat[i].term;
    dw += '">';
    dw += cat[i].term;
    dw += '</a>';
    dw += '</li>'
  }
  dw += '</ul>';
  document.getElementById('show-cat').innerHTML = dw;
  show_post(cat[0].term, 1);
}

document.write('<script type="text/javascript" src="' + cat_home + '/feeds/posts/default?alt=json-in-script&max-results=0&callback=show_cat"><\/script>');
© www.soinside.com 2019 - 2024. All rights reserved.