Search code examples
javascriptcssformatblogger

Blogger javascript not loading css format


I have a script that creates an archive of all my post, with some help we managed to make it work again after changing the domain name and going from https to https, You can read about it here Blogger javascript not working http to https

The problem now is that doesnt load the text format, it outputs the text unformatted looking ugly.

Tried putting the css as a aseparated script but that makes no difference (nor sense).

This is the page where the scrip is: https://www.tecnoriales.com/p/sitemap.html

The style part of the script can be found at the end below

<script>
  var LoadTheArchive = function(TotalFeed) {
    var PostTitles = new Array();
    var PostURLs = new Array();
    var PostYears = new Array();
    var PostMonths = new Array();
    var PostDays = new Array();
    if ("entry" in TotalFeed.feed) {
      var PostEntries = TotalFeed.feed.entry.length;
      for (var PostNum = 0; PostNum < PostEntries; PostNum++) {
        var ThisPost = TotalFeed.feed.entry[PostNum];
        PostTitles.push(ThisPost.title.$t);
        PostYears.push(ThisPost.published.$t.substring(0, 4));
        PostMonths.push(ThisPost.published.$t.substring(5, 7));
        PostDays.push(ThisPost.published.$t.substring(8, 10));
        var ThisPostURL;
        for (var LinkNum = 0; LinkNum < ThisPost.link.length; LinkNum++) {
          if (ThisPost.link[LinkNum].rel == "alternate") {
            ThisPostURL = ThisPost.link[LinkNum].href;
            break
          }
        }
        PostURLs.push(ThisPostURL);
      }
    }
    DisplaytheTOC(PostTitles, PostURLs, PostYears, PostMonths, PostDays);
  }

  var DisplaytheTOC = function(PostTitles, PostURLs, PostYears, PostMonths, PostDays) {
    var MonthNames = ["Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre"];
    var NumberOfEntries = PostTitles.length;

    var currentMonth = "";
    var currentYear = "";

    for (var EntryNum = 0; EntryNum < NumberOfEntries; EntryNum++) {
      NameOfMonth = MonthNames[parseInt(PostMonths[EntryNum], 10) - 1]

      if (currentMonth != NameOfMonth || currentYear != PostYears[EntryNum]) {
        currentMonth = NameOfMonth;
        currentYear = PostYears[EntryNum];

        document.write("<div class='dateStyle'><br />" + currentMonth + " " + currentYear + " </div>");
      }

      document.write('<a href ="' + PostURLs[EntryNum] + '"><div class=dayStyle>' + parseInt(PostDays[EntryNum], 10) + ":&nbsp;&nbsp;</div>" + PostTitles[EntryNum] + "</a><br />");
    }
  }
</script>

<script src="https://tecnoriales.com/feeds/posts/default?max-results=500&amp;alt=json-in-script&amp;callback=LoadTheArchive" />
<script src="https://tecnoriales.com/feeds/posts/default?max-results=150&start-index=151&alt=json-in-script&callback=LoadTheArchive" />
<script src="https://tecnoriales.com/feeds/posts/default?max-results=150&start-index=301&alt=json-in-script&callback=LoadTheArchive" />
<script src="https://tecnoriales.com/feeds/posts/default?max-results=150&start-index=451&alt=json-in-script&callback=LoadTheArchive" />
<script src="https://tecnoriales.com/feeds/posts/default?max-results=150&start-index=601&alt=json-in-script&callback=LoadTheArchive" />
<script src="https://tecnoriales.com/feeds/posts/default?max-results=150&start-index=851&alt=json-in-script&callback=LoadTheArchive" />
<script src="https://tecnoriales.com/feeds/posts/default?max-results=150&start-index=1001&alt=json-in-script&callback=LoadTheArchive" />

<!--CUSTOMIZATION-->
<style type="text/css">
  .dateStyle {
    color: #000;
    font-weight: bold;
    font-size: 15px;
    font-family: Trebuchet MS, sans-serif;
    margin: 0;
  }

  .dayStyle {
    color: #000;
    font-weight: bold;
    font-family: Trebuchet MS, sans-serif;
    display: inline-block;
  }
</style>

It should load formatted text with Trebuchet MS font, using bold for months an dates and also using only one line per item, not two.


Solution

  • It turns out that this isn't anything wrong with your CSS declarations or anything like that as I suspected. The issue is with your feed script calls. Instead of using /> at the end of each, use ></script> instead as shown in the code example below.

    Because these were being called incorrectly, it also stopped your CSS from working correctly since it was defined below the scripts.

    <script>
      var LoadTheArchive = function(TotalFeed) {
        var PostTitles = new Array();
        var PostURLs = new Array();
        var PostYears = new Array();
        var PostMonths = new Array();
        var PostDays = new Array();
        if ("entry" in TotalFeed.feed) {
          var PostEntries = TotalFeed.feed.entry.length;
          for (var PostNum = 0; PostNum < PostEntries; PostNum++) {
            var ThisPost = TotalFeed.feed.entry[PostNum];
            PostTitles.push(ThisPost.title.$t);
            PostYears.push(ThisPost.published.$t.substring(0, 4));
            PostMonths.push(ThisPost.published.$t.substring(5, 7));
            PostDays.push(ThisPost.published.$t.substring(8, 10));
            var ThisPostURL;
            for (var LinkNum = 0; LinkNum < ThisPost.link.length; LinkNum++) {
              if (ThisPost.link[LinkNum].rel == "alternate") {
                ThisPostURL = ThisPost.link[LinkNum].href;
                break
              }
            }
            PostURLs.push(ThisPostURL);
          }
        }
        DisplaytheTOC(PostTitles, PostURLs, PostYears, PostMonths, PostDays);
      }
    
      var DisplaytheTOC = function(PostTitles, PostURLs, PostYears, PostMonths, PostDays) {
        var MonthNames = ["Enero", "Febrero", "Marzo", "Abril", "Mayo", "Junio", "Julio", "Agosto", "Septiembre", "Octubre", "Noviembre", "Diciembre"];
        var NumberOfEntries = PostTitles.length;
    
        var currentMonth = "";
        var currentYear = "";
    
        for (var EntryNum = 0; EntryNum < NumberOfEntries; EntryNum++) {
          NameOfMonth = MonthNames[parseInt(PostMonths[EntryNum], 10) - 1]
    
          if (currentMonth != NameOfMonth || currentYear != PostYears[EntryNum]) {
            currentMonth = NameOfMonth;
            currentYear = PostYears[EntryNum];
    
            document.write("<div class='dateStyle'><br />" + currentMonth + " " + currentYear + " </div>");
          }
    
          document.write('<a href ="' + PostURLs[EntryNum] + '"><div class=dayStyle>' + parseInt(PostDays[EntryNum], 10) + ":&nbsp;&nbsp;</div>" + PostTitles[EntryNum] + "</a><br />");
        }
      }
    </script>
    
    <script src="https://tecnoriales.com/feeds/posts/default?max-results=500&amp;alt=json-in-script&amp;callback=LoadTheArchive"></script>
    <script src="https://tecnoriales.com/feeds/posts/default?max-results=150&start-index=151&alt=json-in-script&callback=LoadTheArchive"></script>
    <script src="https://tecnoriales.com/feeds/posts/default?max-results=150&start-index=301&alt=json-in-script&callback=LoadTheArchive" ></script>
    <script src="https://tecnoriales.com/feeds/posts/default?max-results=150&start-index=451&alt=json-in-script&callback=LoadTheArchive" ></script>
    <script src="https://tecnoriales.com/feeds/posts/default?max-results=150&start-index=601&alt=json-in-script&callback=LoadTheArchive" ></script>
    <script src="https://tecnoriales.com/feeds/posts/default?max-results=150&start-index=851&alt=json-in-script&callback=LoadTheArchive" ></script>
    <script src="https://tecnoriales.com/feeds/posts/default?max-results=150&start-index=1001&alt=json-in-script&callback=LoadTheArchive" ></script>
    
    <!--CUSTOMIZATION-->
    <style type="text/css">
      .dateStyle {
        color: #000;
        font-weight: bold;
        font-size: 15px;
        font-family: Trebuchet MS, sans-serif;
        margin: 0;
      }
    
      .dayStyle {
        color: #000;
        font-weight: bold;
        font-family: Trebuchet MS, sans-serif;
        display: inline-block;
      }
    </style>