Github pages adding random tags to my posts

2019-07-31 17:43发布

问题:

If you visit my website, you'll notice that the most recent article (on the home page) has it's title wrapped in a <pre> tag and is repeated. I have no clue why this is happening.

Here is the post that is being displayed:

---
layout: default
---

Stop distributing .doc files
----------------------------
Monday March 19th, 2012

`.doc` started as a file format used by many operating systems and used to store only plain-text. In the 90's, Microsoft decided to use the extension for Word -- their new word processor. Not only did they decide to use the extension, but they also broke the standard by using a proprietary format, instead of the plain-text most people were used to. Despite the `.doc` extension being more than **10 years old** and the fact that most documents formatted this way render horribly in operating systems other than Windows, I still regularly receive documents in this format. Stop it.

However aggravating the above paragraph is, this article isn't solely targeted at the `.doc` extension -- it is a public plea for people to stop distributing application specific documents and to start distrubting all documents in `.pdf`.

Yesterday I received an email from an engineering society I'm a part of. They were notifying all members of the upcoming annual general meeting that is taking place next week. I immediately lost interest in the email when I saw that their meeting schedule and their nomination form were both in `.docx` format. I don't like being forced to download the file, minimize my browser, launch an Office application (in my case, LibreOffice) and then read the content. Had it been distributed in `.pdf`, Chrome would have immediately opened a new tab for me displaying the document and giving me options to save, zoom or print it. I'm sure Firefox, Opera and (maybe) Internet Explorer have similar features.

We are increasingly collaborating on the web, and the need for bulky desktop applications are almost gone with the wind. Had I not had an office application on my computer (which could have been possible seeing as I do most of my documentation and report with LaTeX), I would have had an extra step before viewing the content that was sent to me. It's not like it is difficult either. All major office applications I know of allow easy exporting to `.pdf` file format and LibreOffice also allows you to save a hybrid `.pdf` and `.odt` together in one file. This allows you to distribute the PDF as is and also open it for editing.

There is virtually no need to distribute documents in any format, proprietary or not, other than PDF. Don't make your users work and fiddle with your flatform-specific or application-dependent documents.

And here is my default layout (the relevant part, you can view the source for anything else):

<div id="right-side">

            {{ content }}

            <div id="footer">
                <p>
                    &copy; {{ site.author.name }} 2012 with help from
                    <a href="http://jekyllbootstrap.com" target="_blank">Jekyll Bootstrap</a>
                </p>
            </div>
        </div>

as you can see, the layout simply dumps the content of the markdown file in the right-side div. If you visit the other pages/post on my site, you'll see that those pages work but not the homepage (despite them being in the same markdown format and using the same layout).

Any ideas?

回答1:

The problem is the loop on your index page. The indentation is (sort of) preserved by Liquid: the text replacement is a literal substitution which means the first line will be indented but later ones won't. The markdown processing of index.md (first.content is already HTML) happens after Liquid runs, so the indentation is interpreted as a code block.

The steps in the processing (this isn't necessarily the verbatim output at each step, but it would be close):

{% for first in site.posts limit:1 %}
    {{ first.title }}
    {{ first.content }}
{% endfor %} 

After Liquid has run on index.md:

    Stop distributing .doc files
    <h2>[...]</h2>

<p>Monday March 19th, 2012</p>

[...]

Now Markdown runs, and the indentation means that the first two lines are a code block:

<pre><code>Stop Distributing .doc Files
&lt;h2 id='stop_distributing_doc_files'&gt;Stop distributing .doc files&lt;/h2&gt;</code></pre>
<p>Monday March 19th, 2012</p>

This can be fixed by not having such a large indent of the elements of the for loop: indenting by 4 spaces or a tab makes code block. So

{% for first in site.posts limit:1 %}
  {{ first.title }}
  {{ first.content }}
{% endfor %}