Jekyll on Github suddenly do not work because of 'nil' date - github

Well, I swear I changed no setting at all.
I setup my Jekyll blog, and it did work before.
Every time I want to write something new, I just copy and old post file, rename it to the current date and modify the content within it.
But just one day, after I push my new content to Github, I received an email, noticing me that
The page build failed for the master branch with the following error:
The value 'nil' was passed to a date-related filter that expects valid dates in /_layouts/post.html or one of its layouts. For more information, see https://help.github.com/articles/page-build-failed-date-is-not-a-valid-datetime/.
For information on troubleshooting Jekyll see:
https://help.github.com/articles/troubleshooting-jekyll-builds
First, I did not modify /_layouts/post.html. Second, I do not use date info in YAML, because Jekyll already uses the strong name requirement like YY-MM-DD-title.md.
I am just some guy who wants to write something fun but knows little about IT tech. I searched the Jekyll doc, and read the post on StackOverflow like below:
Invalid date while building on Github Pages
But as my post.html file content is different from that post, I do not know what I can do.
I built it on my Mac with bundle exec Jekyll build, it just shows the same information as the email
$ bundle exec jekyll build
Configuration file: > /Users/zhanglidong/Documents/ASyncFiles/jetorz.github.io/_config.yml
Source: /Users/zhanglidong/Documents/ASyncFiles/jetorz.github.io
Destination: > /Users/zhanglidong/Documents/ASyncFiles/jetorz.github.io/_site
Incremental build: disabled. Enable with --incremental
Generating...
Liquid Exception: Invalid Date: 'nil' is not a valid datetime. in /_layouts/post.html
ERROR: YOUR SITE COULD NOT BE BUILT:
------------------------------------
Invalid Date: 'nil' is not a valid datetime.
My GitHub repo: https://github.com/jetorz/jetorz.github.io
My jekyll blog: https://jetorz.github.io/
How can I fix it? Any one who wants to help the pity me? :(

Like answer above suggested,
I rechecked the link I provided:
Invalid date while building on Github Pages
There is and if block outside the <time> part.
I do not know much about Liquid,
But I think it worth trying.
So I add this if to my post.html like below
{% if page.date %}
<time datetime="{{ page.date | date_to_xmlschema }}" itemprop="datePublished">
{% assign date_format = site.minima.date_format | default: "%b %-d, %Y" %}
{{ page.date | date: date_format }}
</time>
{% endif %}
I do not know exactly what it is about,
but It does work :)
Now again I can post my blog.

Related

Creating two blogs on same website (Jekyll GitHub) without altering layout/formatting

I have recently tried creating a website using the Jekyll GitHub template here. One major alteration I hope to make to this template is to have two "blogs" in the format provided in the Blog tab of that template specifically shown here.
I (sort of) successfully created two blogs in my website and named the associated tabs (Media) and (Blog). I achieved this by reorganizing the file structure to have a "media" folder and a "blog" folder separately that each contain a _posts folder and index.html file. Now, when I add .md files in the _posts folder, these posts seem to get added to the correct tab (Media or Blog).
Even though that functionality works, both the Blog and Media tab lost their aesthetics compared to the style in the original template blog. Namely, 1) the banner image at the top is now gone; 2) the text formatting with the title in one line followed by the date in the "pretty" format (gray colored and in the format 29 Aug 2016) is now in a less-attractive bullet format with date first and in the format Aug 29, 2016; 3) the introductory excerpt text (in the example: "A pot still is a type of still used in distilling spirits such as whisky or brandy. Heat is applied directly to the pot containing the wash (for whisky) or wine (for brandy).") is now gone.
It is unclear to me why my separation of the _posts folder into two separate folders seems to cause these unwanted layout side effects. Since all three of these layout issues changed at once, I am assuming they can all be solved in the same solution. Whether or not that is true, any advice on how to solve these layout issues could be very helpful. Thank you for sharing any ideas!
You've removed the posts collection from your _config.yml which was setting the default feature_image for all posts. Unless you add that back in or include the overrides in each individual post it will not display the header (it may or may not also affect the rest of the styles):
collections:
media:
title: Media # Needed for Siteleaf
output: true
description: "Recent discussions with the media." # The post list page content
feature_text: |
Sharing our motivations and
opinions with the media.
feature_image: "https://picsum.photos/2560/600?image=866"
You're not actually using a media collection in either blog/index.html nor media/index.html, you're using the post.categories for filtering in the end, which will still causes some weird pagination once you start getting things rolling.
You may want to look at using the separate collections and then pre-building your site using paginator v2 (https://github.com/sverrirs/jekyll-paginate-v2/blob/master/README-GENERATOR.md) which will allow for pagination of different collections.
Edit 2020-01-23
Taking a new look at your repository, you still only have one (posts) collection. Therefore the logic for reading feature_* is being shared. If you look at the include site_feature.html you can see how the feature_image is being parsed out of the collections.
{% assign collectiondata = site.collections | where: "label", page.collectionpage | first %}
Which in your case is why Blog and Media both have the second image ?image=213. Your blog.html and media.html still have the front matter collectionpage: post.
I still think you're going down a slippery slope which will result in things not working exactly as you want them once you get more and more posts by doing it this way.

Getting search bar to work with Hexo-Algolia

There's some issue with the old algolia account so I've to create a new one, with new App ID and API key etc., for testing with updated contents but now my search-bar wouldn't work.
So what's in the current _config.yml file is as followed:
algolia:
en:
api_key: c3d5d4c995b5e0c2ffb5623900279a66
index_name: hexo
zh-cn:
api_key: cdea7d4e47d84f6145b77e7f68689f35
index_name: hexo_zh-cn
and it's actually working fine with search bar showing. Just that the search-contents are wrong.
So with my new set of ID and API keys, I tried to simply replace the above api_key with the new one and running the hexo algolia command, the following error was shown:
ERROR [Algolia] Please set a `HEXO_ALGOLIA_INDEXING_KEY` environment variable to enable content indexing.
ERROR >> Read https://npmjs.com/hexo-algolia#api-key for more informations.
I followed the documentation for algolia, with the following amendment to the _config.yml and the hexo algolia command works like a charm:
algolia:
applicationID: CDWIP9PSJ7
apiKey: 218de3a558ce35814a7ac580345770a5
indexName: hexo
However, here's come the issue, my original search bar wouldn't appear anymore :/ I've noticed it's probably due to the missing en: & zh-cn:, but when I added those in, my hexo-algolia command wouldn't work again with the following error:
FATAL Something's wrong. Maybe you can find the solution here: http://hexo.io/docs/troubleshooting.html
AlgoliaSearchError: Please provide an application ID. Usage: algoliasearch(applicationID, apiKey, opts)
So now I'm puzzled, how is the old code able to work without the Application ID? and comes to the question, is there a version upgrade to Algolia and therefore an update to the format as well?
I'm actually more concern on how to get the search bar to appear again but I believe the above question can hopefully lead me to solve the issue. But for those who happen to know, help is greatly appreciated!
I believe the "search-bar with algolia script" connection is related to the after_footer.swig file with the following original code:
<!-- Algolia -->
{% if config.algolia[page.lang] %}
<script type="text/javascript" src="https://cdn.jsdelivr.net/docsearch.js/1/docsearch.min.js"></script>
<script type="text/javascript">
document.getElementById('search-input-wrap').classList.add('on');
docsearch({
apiKey: '{{ config.algolia[page.lang].api_key }}',
indexName: '{{ config.algolia[page.lang].index_name }}',
inputSelector: '#search-input'
});
</script>
{% endif %}
Much thanks in advance!

Remove "by [username]" in a GitHub Pages document.title

I have a GitHub Pages site, and I don't want to use the raw html to develop the site yet because non developers on the team will be pushing.
The problem is that the document.title contains "by [username]" at the end. I want to remove that and just make it be the beginning text.
I already tried title: [custom title] in Jekyll and it still has the organization name at the end.
I am using the Midnight theme.
Thanks!
As based in comments, you are using the jekyll-midnight-theme, copy the default layout file of the jekyll-theme-midnight repo into _layouts directory in your Jekyll website.
Create the /_layouts directory
Copy https://github.com/pages-themes/midnight/blob/master/_layouts/default.html into /_layouts
Now edit /_layouts/default.html and adjust the <title> HTML tag, in this case removing the "by " part, so this:
<title>{{ site.title | default: site.github.repository_name }} by {{ site.github.owner_name }}</title>
replace it with:
<title>{{ site.title | default: site.github.repository_name }}</title>
Now your website won't include the "by [organization name]" at the end.

Can I cause JsDoc3 to omit the <footer> tag with the date in it?

JSDoc outputs a date in the footer of each page:
<footer>
Documentation generated by JSDoc 3.2.0 on Fri Jan 17 2014 14:30:54 GMT-0800 (PST)
</footer>
So whenever I rebuild my library, all the documentation files look like they've changed to Git. That's not desirable -- I only want to commit these docs when they actually change in content.
Can I cause JsDoc to not output this footer at all?
I submitted a PR for this issue (https://github.com/jsdoc3/jsdoc/pull/916), and it's now on the 3.3.0 branch.
This change was not published to NPM at the time I'm writing this answer, but you can require the 3.3.0 branch from git:
"jsdoc": "git+https://git#github.com/jsdoc3/jsdoc.git#releases/3.3"
Afterwards, you can add the following field to your config file:
{
...
"templates": {
...
"default": {
"includeDate": false
}
},
...
}
Notice this option is only available for the default jsdoc template.
I have some modest experience with creating jsdoc 3 templates and I've looked at the code to check what you are asking. Here is what I found:
<footer> is hardcoded in the default template's layout.tmpl file. By hardcoded, I mean the element itself is not optional.
I've not seen any code in the default template's publish.js file that would somehow remove <footer> when processing layout.tmpl.
So to remove this footer you'd have to use a customized template or do some sort of post-processing on the files generated by jsdoc 3.
With versions prior to 3.3.0, removing <footer> from the template would mean copying the whole default template and making the change to layout.tmpl. Version 3.3.0, which is currently in alpha, will provide the possibility to basically tell jsdoc 3 to use the default template but with a different layout.tmpl file, which will make customizing templates much easier.

How to render a Jekyll markdown page on sites index

I'm probably missing something simple but I have no way to test Jekyll locally.
I'm using GitHub pages to render Jekyll, for starters I only want to render markdown content on the main index.html from one markdown page.
The structure is:
Index.html
---
layout: default
---
_layouts
- default.html
//html stuff..
<section>
{{page.content}}
</section>
In root folder I have a page called content.md that I wish to render for {{page.content}} the layout renders but the liquid tags section is blank.
How do I render content.md?
Example: https://github.com/wycks/wordpress-gears-jekyll
There are a few things going on here.
In your _layouts/default.html file (and any of the other _layouts directory files for that matter), instead of:
{{ page.content }}
you need to use:
{{ content }}
Jekyll only lets you includes files from a site root level _includes directory. So, you need to move your content.md from the root to that directory (making it if it doesn't already exist).
Finally, you need to actually make the call to the include file from your index.html file. This can be done by changing the content of your index.html file to:
---
layout: default
---
{% include content.md %}
That will setup the behavior you are looking for.
I'd point out two other things:
You may find that changing the extension of your index file from .html to .md works better. An important note though: you need to use .html if you want pagination. Per the Jekyll Pagination documentation, that feature only works when the file is named index.html.
If all you are doing in your index file is calling an include that only resides on that page, you might be just as well off simply putting the content directly in the index file.
include only allows you to include files directly under _includes/. There is is also include_relative which allows you to use paths and include from other places. The include has to be relative to the given file however:
{% include_relative somedir/footer.html %}
There is one issue with either include method I can't resolve: If the file you include has front matter Jekyll won't strip it out. So you can't use front matter to store include specific meta data - like say "title". Of course you can use variables - {% assign title = "My Title" %} but it's not equivalent, because if you want the thing your including to be part of a collection or rendered independently you have to have a front matter.
I believe it is just
{{ content }}
good sir.
ref