Configuring per-directory permalink settings in jekyll - configuration

Is it possible to have different permalink settings for different directories?
For example, if I have a Jekyll setup where blog entries are written into /blog/_posts/ and news items in /news/_posts, then by default each entry will have permalinks in the format /blog/2011/06/24/slug.html and /news/2011/06/24/slug.html.
The permalinks for blog entries are fine as they are, but I need to change the permalinks format for news to something different, say /news/2011/slug.
I've tried changing the permalink settings in the YAML front matter for the layout used by news item, however, this does not work since permalink settings in YAML front matter are not interpolated (as confirmed in the answer to this question).
Is there a mechanism to configure path specific settings in _config.yaml? Or is there a better what to achieve this results?

Not sure if this will be any help now but I ran into the same problem trying to make a blog/portfolio and wanting to have /articles/2013/.. and /work/2013/..
What I did is just change the permalink to:
permalink: /:categories/:year/:title
and added 'articles' as a category for my blog posts and 'work' as a category for my work and it worked fine.

Just got inspired by jose's comment. Why not do this:
permalink: /:categories/:title
and then in the front matter for your blog just do
categories: blog 2013 05 01
for news only do
categories: news 2013

The only way you can achieve that is by having two different jekyll instances.
You could have (for example) a full site with the pages and blogs, and a "microsite" inside the news folder, with it's own ´_config.yaml´ . The "top" would have to ignore the news directory completely, and the news directory would have to be configured to generate its output inside "../_site/news".
The biggest hurdle would be that you would not be able to run Jekyll as a server; you would have to use a script (i.e. a Rakefile) to generate the static pages for both jekylls, and serve them with a different server (i.e. unicorn).
Like I said, it'd be a bit of a hurdle, but doable in 1h or less.

Related

Can Jekyll serve files when a directory of the same name exists?

I have a simple use case on a site that I am publishing with Jekyll:
I need to list values of a certain type. Let's say one type has URIs of the form .../base/typex/value. I am generating a file .../typex/value.md and Jekyll happily serves it.
I also want to serve pages listing all values. That page should be named .../base/typex or .../base/typex/ (I don't mind either way).
I cannot use the file .../base/typex/index.md to do this because in some cases, index is actually a valid value.
I am creating .../base/typex.md, but Jekyll ignores it, regardless of the permalink that I put in there that specifically has no trailing slash. Instead of serving the file, Jekyll serves the directory listing.
Is there any way I can solve this puzzle? If Jekyll had support for serving .../base/typex.md, everything would be good, but it seems as if as soon as there is a directory .../base/typex/, Jekyll simply ignores this file. Is there any workaround or configuration I can use? (And this is going to get hosted on GitHub, so I have no control over the Web server configuration.)
( https://github.com/dret/webconcepts/issues/25 has the backstory, in case anybody is interested. But the issue is fully described here, so there is no need to follow that link. )
I just tried to reproduce it with your provided repository, thanks for that!
If you create a file http-method.md in /concepts and set the permalink to
permalink: /concepts/http-method/, my local jekyll serves the page both in /concepts/http-method and /concepts/http-method/

How to make posts private in Hugo?

I am looking for ways to make some of the posts on my blog visible only to myself but can't seem to this in Hugo.
Is there any way around this such as setting a password for certain posts?
Or is the feature supported but I just haven't found it?
Since Hugo just generates the static HTML, the question can be widened to: how to password-protect any static content on the web server.
That's doable.
It depends what is your web server using: Apache or Nginx or something else.
In Apache case, set up password authentication via .htaccess. See tutorials like this.
In Nginx case, set up password on your server block section, see tutorials like this.
For other server (IIS?), google accordingly.
Some people will want to downgrade this question, but in my opinion it's very valid, for example, if you want to post portfolios, CV's and whatnot on your personal website and limit public access
Make a landing page on Hugo site, password-protect the URL and give visitors the password. Easy, fast and still static!
My way to keep posts private is to set the draft flag in the front matter:
TOML
draft: "true"
A good practise for me is to connect a local instance of Hugo with GitLab/GitHub. If you want to see your website or a specific post as a rendered version you can turn on and off the visibility of pages using the draft flag with true and false.
If you have finished your tests you can push the final version with or without the draft flag active to the repo and sync it with your server side installation of Hugo.
Posts are displayed in multiple places (RSS feeds, search results, sitemap etc.).
Here is an article with an updated checklist and a solution to publish hidden posts with Hugo
Installation
git clone --recurse-submodules git#github.com:RoneoOrg/hugo-offtherecord-demo.git
cd hugo-offtherecord-demo
hugo serve
Usage
Set offTheRecord to true in the Front Matter of the posts you want to hide. That’s all!
See the source for details

Jekyll/Github Pages -- index.html not being written?

Cross-posted in a Github issue at https://github.com/SeanKilleen/seankilleen.github.io/issues/189
Digging into an issue with GitHub pages that appears like it might be recent.
I noticed an up-tick in 404s via Google Analytics. It appears that posts with trailing slashes are becoming 404'd, but appeared just fine without the slash.
My local Jekyll instance generates the following structure for how-to-leave-a-company-well.md from Feb 2015:
/2015
/02
/how-to-leave-a-company-well.html
/how-to-leave-a-company-well
/index.html
So, the following URLs work just fine locally:
http://localhost:4000/2015/02/how-to-leave-a-company-well
http://localhost:4000/2015/02/how-to-leave-a-company-well.html
http://localhost:4000/2015/02/how-to-leave-a-company-well/index.html
http://localhost:4000/2015/02/how-to-leave-a-company-well/
Those last two URLs that I've bolded do not seem to exist on my published site after GitHub Pages generates the documents.
I cannot reach http://seankilleen.com/2015/02/how-to-leave-a-company-well/ or http://seankilleen.com/2015/02/how-to-leave-a-company-well/index.html
This seems to indicate to me that GitHub Pages is doing something differently than my Jekyll installation. Given that the 404 spike is recent, I'm wondering if there might have been a change related to this.
Does anyone have a thought on how I might be able to diagnose this? It's a bit of a black box for me when my local is doing what I expect and I can't see the Github Pages process.
Jekyll 3 changed the way the permalinks worked, and dropped the trailing slash if your permalink setup did not contain one - yours does not contain a trailing slash at the end of your permalink in the config file. Jekyll 3 now respects that and thus your page is a 404 when there is a trailing slash in the url (since you want it without it).
https://jekyllrb.com/docs/upgrading/2-to-3/#permalinks-no-longer-automatically-add-a-trailing-slash
You may want to check which version of jekyll you have installed - you may be on 2.x and GH is now 3.x
When working locally, are you telling jekyll to use the GH pages gem? if you
don't do this you may get different behavior on GH than local. I do not do this, so I can't tell you how to do it (or if this particular issue would happen), but I do know that you should do it if you want to preview locally what you will get when serving via GH.

How to change paths and URLs in Jekyll?

I am very new to Jekyll and I am failing to find configuration to change the following:
I built a basic Jekyll site using jekyll new . and ran jekyll serve to learn and built a layout using Jekyll. The basic test site gives me the following URL for posts: /jekyll/update/2016/01/30/welcome-to-jekyll.html. Is the URL like that because I am running jekyll serve and not jekyll build? I want to remove the the jekyll/update from the URL path, so my final URLs for posts look like the following: /2016/01/30/welcome-to-jekyll.html.
I want my pages to be stored in a separate directory _pages instead of the root directory. How can I do that?
Is there way to prepend a path to files loaded from a specific directory? For example, I want to make a /_projects directory. Then add files with the following permalinks: /prj-test1, /prj-test2, /prj-test3. When compiled, I want to get the following URLs: /projects/prj-test1, /projects/prj-test2, /projects/prj-test3, respectively. Is this possible?
Yes, everything you asked is possible.
Take a look at these examples, you might want to choose one of them. But to do as you asked, you'll need to change the permalink to /:year/:month/:day/:title.html. To do that, add this line to your _config.yml file:
permalink: /:year/:month/:day/:title.html
It depends on the structure you want to achieve. You can use collections or simply create pages inside a folder called pages (without the underscore).
Yes. You can do that via collections, for example.
I recommend you to take a look at some templates, so you can see how the code works in different ways:
Try some Jekyll Themes here and here. Download them and study their structures.
If you want to go deep, take a look how Jekyll build its own website.
Hope to have helped!

jekyll pretty permalinks give me WEBrick error

I am developing my blog in Jekyll (3.0.0 beta), currently on localhost,
When i am trying to implement the pretty permalink and i try to visit a post it shows a WEBrick error.
If i apply the /:year/:month/:day/:title.html it works fine do you have a clue why isn't it working with pretty permalinks?
This is the error I get:
/2015/08/03/are-permas-working.html' not found. WEBrick/1.3.1 (Ruby/2.1.6/2015-04-13) at localhost:4000
Once you set Jekyll permalinks to pretty in _config.yml like so:
permalink : pretty
... and restart your WEBrick server (a restart of the server instance using jekyll serve or bundle exec jekyll serve [if following GitHub] is needed for the new values to take effect, your permalinks will no longer be in the format of YYYY/MM/DD/title-slug.html since they are now "pretty". The new format for your links will be /:categories/:year/:month/:day/:title/. This is in accordance to the format determined by the pretty variable as defined here in the documentation.
What this means for you is that your original link for the 'Are permas working' post is no longer at localhost:4000/2015/08/03/are-permas-working.html, rather they are now at localhost:4000/2015/08/03/are-permas-working/ since you don't have a category defined.
You're experiencing this error because after you've made the change and restarted your server you most likely did not navigate to the post from your homepage (which will have that new link to point to the post), rather you just refreshed the page on your browser, which will throw a 404 since the page is no longer there.
Bonus, Jekyll makes posts pretty by creating folders 2015 -> 08 -> 03, and then a folder for that specific post, with an index.html inside it.
Also, if you wanted "pretty-fied" links that don't have the dates there, you'll need to manually specify that using this:
permalink: "/:categories/:title"
This ensure will hide the .html extension and also get rid of date values.
EDIT: From the comments I stated that using /:title for permalinks might not work since there are conflicts with non-post pages, I stand corrected. If you wanted short permalinks like user.github.io/title-of-blog-post/ you would just need to set permalink : /:title and you're good to go. However, if you have non-post pages such as an about page, a credits page, you should explicitly set permalinks on those pages to be /about and /credits on the YAML frontmatter to avoid the edge case of also having a blog post with the title about and accidentally overwriting the non-post page.