I just shifted my entire blog from WordPress to Jekyll. There are still some pieces that need fixing here and there, but I am facing this problem at the moment. I am unable to generate sitemaps in Jekyll. I saw that there are a couple of plugins which can do the work for me.
Information on the site:
Site hosted via Github pages
Entire site handcoded - not using JB or Octopress
It would be great if you I could get some pointers towards how to do the required.
Note: This question is not the same as it's predecessors. I am not looking for options which use _site.
As explained by John Day in this article, you can create a sitemap.xml file in the site's root with this content:
---
layout: nil
title : "Sitemap"
sitemap_exclude: y
---
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
{% for post in site.posts %}
<url>
<loc>{{site.production_url}}{{ post.url | remove: 'index.html' }}</loc>
</url>
{% endfor %}
{% for page in site.pages %}
{% if page.sitemap_exclude != 'y' %}
<url>
<loc>{{site.production_url}}{{ page.url | remove: 'index.html' }}</loc>
</url>
{% endif %}
{% endfor %}
</urlset>
In _config.yml, define a variable named production_url with the site's full base URL (e.g. http://example.com).
If you want to exclude any links from the sitemap, include sitemap_exclude: y in the front matter of the page or post.
For a more advanced example refer to this article: Building a Better Sitemap.xml with Jekyll.
You could create a new file in your site root called 'sitemap.xml', and within that page use liquid tags to iterate over all pages and posts extracting the necessary data. Seems like that would do the job pretty easily, assuming that you just want to generate a page which lists every page on the site in an xml format that conforms to the appropriate standard.
Just came across this because my site is hosted on github-pages.
It seems github pages now supports this.
Just had to add to _config.yml:
gems:
- jekyll-sitemap
(You can optionally add to your Gemfile, but mine was already included via dependency)
(fun fact: jekyll-redirect-from is also supported by github pages)
You can not automagically generate a full sitemap in jekyll without using plugins.
What you could do is make your own ruby (or else) script that generates a sitemap as JSON data and then insert it in your config.yml. From there you could access that data from jekyll and display it.
But there is no built-in way to do that just with jekyll.
Related
can someone help me?
I have a Jekyll site on netlify (http://127.0.0.1:4000/) that is working great.
I followed this tutorial to create a Jekyll admin path with CMS (http://127.0.0.1:4000/admin) to administrate the posts I want to write.
Basically, I created a new admin folder with two files, index.html and config.yml. My new file config.yml is like so...
It is working properly, I can create and update the posts on the _posts folder as expected.
Wherever, I'm trying to create a blog on a subpath of that site, like http://127.0.0.1:4000/blog for loop through the posts on _posts on such path, but I doing something wrong and can't figure out what is it.
The last thing I tried was to create a collection for the posts on the main file _config.yml like so...
I tried two permalinks, add/remove the folder and add layout, but I think I'm forgetting something.
To help you guys understand the whole project, my index.html has
---
layout: default
---
and the layout default is on the folder _layouts and contains many imports that are on the folder _includes.
Finally, I tied to loop through the collection of _posts on index.html adding code like bellow on the file posts_list.html that was imported as you can see above...
<h1>Latest Posts</h1>
<ul>
{% for p in site.posts %}
<li>
{{ p.title }}
<!-- {{ p.excerpt }} -->
</li>
{% endfor %}
</ul>
and also creating a new html file called posts.html on the same folder of index.html with the same code above, but in both cases the posts are not rendering.
Finally, this is my whole project...
If you want more info about what I'm doing, just ask,
Thanks for helping me...
[UPDATE 1]
My posts are .md files, here is an example...
As you can see I also created some extra layouts, one for compiling all posts blog and another for show the post itself post.
Change the extension to .md (on your posts and index file) and add frontmatter, referencing your template. Your posts.md and index.md files should look like this:
---
layout: default
---
Check for errors... if there are none it should output just fine.
UPDATE
Thank you for sharing your code at https://github.com/nielsenrechia/nr.github.io.
I see that you created random comments in your config file. They mess things up. Clean up your config file and use the right indents and new lines. Check out the Jekyll documentation at https://jekyllrb.com/ for help. Further you seem to reference your posts by calling site._posts. That should be site.posts. Finally, you do not need to specify the posts collection in the config file. It is assumed that it exists and uses the _posts folder.
Here is an image of the working posts section:
I am having trouble with this seemingly simple task..
Can someone help please?
I have uploaded .ico file to /usr/lib/ckan/default/src/custom_theme/ckanext/custom_theme/public
Changed value in setting file (development.ini)
Tried making base.html for the custom theme, with
{% ckan_extends %}
{% block links -%}
<link rel="shortcut icon" href="http://site.address/favicon.ico" />
{% endblock -%}
For file path, I have tried both relative and literal.
I can access the icon file if I type in address of it in web browser.
This is what works for me*:
Define favicon filename in your .ini eg. ckan.favicon = favicon.ico
Upload file to ../ckan/default/src/ckanext-[your_theme]/ckanext/[your_theme]/public
Reload apache
Clear Browser cache
Reload site in Browser
This assumes CKAN >2.5 and following instruction on creating a custom theme
No need to change the base.html file in custom theme.
In CKAN 2.9.0 replace /usr/lib/ckan/default/src/ckan/ckan/public/base/images/ckan.ico with your ICO file.
Assuming you have:
ckan.favicon = /base/images/ckan.ico in your ckan.ini
Refresh your browser.
I'm using Jekyll, which uses the Liquid Template language. I've used Jinja templating in the past, and it has the concept of a macro (just a named function). Does Liquid have something which provides equivalent functionality? If not, is there some Jekyll plugin which will extend Liquid to provide it?
You can create includes that accept parameters. It's not quite a macro but it's what I've used successfully on GitHub Pages.
More details and tips for managing includes and using parameters can be found in the Jekyll documentation.
Here's an example:
_includes/email_link.html
<a href="mailto:{{ include.user.email_address }}"
title="Email {{ include.user.name }}">
<i class="fa fa-fw fa-envelope"></i>
</a>
about.md
---
layout: page
title: About
---
{% include email_link.html user=site.users.erik %}
_config.yml
users:
erik:
name: Erik
email_address: erik.gillespie#wizbang.com
This is exactly what Jekyll tags plugins are made for.
I'm building a website in Jekyll. To remove html extension in posts I added the following to _config.yml
permalink: /kb/:title
To remove html extension from pages, I created folders for each page, and placed an index.html file in each page folder.
Now the posts and pages work without html extension, but when I link to a page with page.url it returns the whole link (/kb/index.html) instead of just /kb.
What variable can I use to link to a page without html extension?
The value returned by {{ page.url }} reflects what the permalink for the page is.
To get the urls to not include the "index.html" part you will need to add a permalink setting to the front matter for each of these pages. This actually removes the need of having all the files named "index.html" and in separate folders.
So your front matter would contain something like:
---
permalink: /scratchpad/level/relative/
---
Note the trailing slash, if you omit this then Jekyll would create a file called "relative" instead of a directory containing an index.html file.
I am at my wits end here. I've been trying to look at all other example github project pages I could find and even the blogs but none exhibit the problems I am getting. First, I am trying to create a project page for my repo. I did this by following the usual tutorials, creating a gh-pages branch in my project repo and pushing.
I managed to do these and template my files. I even managed to use HAML and SASS(they still both get converted to html/css and that's what I push to the repo so no problem there). I just think that I am configuring my jekyll wrong. First, I don't see any configurations in other people's pages that use baseurl or url on config.yml.
The problem with mine is when looping through my posts:
{% for post in site.posts %}
{{ post.title }}
{% endfor %}
It always generates the href as href="/post-title"
my _config.yml btw only has this:
permalink: /exercises/:title
The problem with this when I click the link, it always points to http://corroded.github.com/exercises/title-here when it should actually be http://corroded.github.com/projectname/exercises/title-here
I have actually tried hard coding the path by doing:
<a href="http://corroded.github.com{{ post.url }}"> and this works. It goes to the post BUT it shows it as plain text and not as the generated html. I know I am missing something very simple here but I can't seem to find it and I've been wrestling with this the whole weekend.
Oh and I forgot to add: doing this in my localhost, I can access everything at:
http://localhost:4000/ and clicking on links will get me to http://localhost:4000/exercises/title-here and IT WORKS. So I have a pretty good guess that it has something to do with the configuration.
EDIT: This answer has been added to the Jekyll documentation at http://jekyllrb.com/docs/github-pages/.
I finally figured out the trick, if you're looking for a solution with the standard URL for GitHub Pages (username.github.io/project-name/). Here's what to do:
In _config.yml, set the baseurl option to /project-name -- note the leading slash and the absence of a trailing slash.
Now you'll need to change the way you do links in your templates and posts, in the following two ways:
When referencing JS or CSS files, do it like this: {{ site.baseurl }}/path/to/css.css -- note the slash immediately following the variable (just before "path").
When doing permalinks or internal links, do it like this: {{ site.baseurl }}{{ post.url }} -- note that there is no slash between the two variables.
Finally, if you'd like to preview your site before committing/deploying using jekyll serve, be sure to pass an empty string to the --baseurl option, so that you can view everything at localhost:4000 normally (without /project-name getting in there to muck everything up): jekyll serve --baseurl ''
This way you can preview your site locally from the site root on localhost, but when GitHub generates your pages from the gh-pages branch all the URLs will start with /project-name and resolve properly.
More conversation about this problem on issue #332.
When you have a slash at the front of your permalink, it means that all URLs should be relative to the site root. This is the reason that it's going to http://corroded.github.com/exercises/title-here instead of http://corroded.github.com/projectname/exercises/title-here. Try it without the first slash:
permalink: exercises/:title
The same thing goes for any URLs you create with HTML. If you have:
<a href="/about">
it will always go to the root of the domain (e.g. http://corroded.github.com/about). If you're project is called 'projectname', you can use HTML like
<a href="/projectname/about">
to link directly to pages (e.g. http://corroded.github.com/projectname/about).
Of course, you can also use relative URLs (i.e. URLs without a leading slash) as well. You just have to be aware of where you are in the directory tree.