How to separate Jekyll posts into two different folders? - jekyll

I have a _posts folder and I just want a simple way to separate the posts in the folder into two different folders, and not have any permalink changes, for purely organizational reasons.

Just create subdirectories in your _posts directory; the subdirectories will be ignored when Jekyll generates permalinks.

I recently did this to my _posts folder because I have over 200 files. I decided to create folders that represent each year I have a posts for. Doing this though, broke post_url. The error is something like as follows when you run jekyll build
Liquid Exception: Could not find post "blah-blah" in tag 'post_url'. Make sure the post exists and the name is correct. in _posts/2007/blah-blah.md
I had to go back in and where ever I used post_url, I had to add /year/ in front of each post url links.
https://github.com/jekyll/jekyll/issues/1714#issuecomment-28167702

Related

Jekyll: Manually whitelist directories and files to be copied to _site directory

Is it possible to specify a list of files or directories that one would like copied to the _site directory? I would like to copy those files as is, in the way the webpack-copy-plugin lets one use webpack to copy files from on place to another.
The files I want to copy are in _includes, in case this complicates things. I know I could make a top level directory in my project for these files I want copied to _site, but I want to keep things tidy and place everything in _includes (Jekyll already makes lots of files and folders in my project root, and I don't want any more).
I tried specifying the value for include in _config.yml, but this doesn't seem to be copying file to _site.
Any suggestions others can offer would be helpful!
Curious, specifying in _config.yml:
include:
- _includes
Copies over everything from _includes, while specifying:
include:
- _includes/assets
does not copy over anything. I'll just use the former.

How can I "watch" multiple source directories in Jekyll?

I'm pretty sure I've seen in Jekyll blog projects with multiple source document directories, such as _posts and _pages, but the source parameter in the _config.yml file can only take 1 directory as its argument, and neither an array nor a space separated string of directories works.
Am I misunderstanding the meaning of the source parameter? I'm expecting it to be used by watch to specify which files' changes will trigger a build, and which files to build.
Also, I have fragments such as about.md which can be included in other pages. What is the best location for files like this one?
The source configuration refers to your <project_root>, not individual directories within the project root. By default, its set to your current_directory (the location from where you are running jekyll build (or) serve.
Jekyll watches all nested files and directories deep within the source directory by default.
about.md is not meant to be seen as a fragment to be included in other files. Its a full-blown "page" that would render into _site/about.html or _site/about/index.html depending on your permalink settings.
Fragments to be included in other pages live inside the _includes directory and are inserted via the Liquid construct {% include <fragment-filename>.html %}
Other than _layouts, _includes and _sass, directories that start with an underscore are ignored by Jekyll unless you configure Jekyll to see them as "collections". _posts is a pre-defined and hard-coded collection directory.
For more information on Jekyll, refer the official documentation at https://jekyllrb.com
If anyone, like me, is looking to include several source folders in github-pages, you can simply configure the jekyll root in github-page on the master branch. I.e. not on gh-page branch, nor on the docs folder.
Thus, all folder is processed. README.md are treated as index.md and you can easily make relative links from the main README.md at the root to any other doc which are "below" it in the file hierarchy. Thus having jekyll cover all your code documentation.

Adding non-text files to `_posts` in Jekyll

Short story: I want to be able to store non-text files/directories in the _posts/ folder.
This is not about local assets, or anything like that. I literally just want to store files (non-associated images and directories) there for a specific, unrelated issue that doesn't merit discussion.
Is there a way to put a folder in _posts/ and in essence have Jekyll ignore all of its contents? Or at least, not freak out about the contents being non-text files?
EDIT: It seems that the actual errors are coming from the names of some of the sub-subdirectories. When the name of these directories start with a date, it gives me the error:
Liquid Exception: invalid byte sequence in UTF-8 in /Users/burchill/burchill.github.io/_posts/blah/source/2017-1‌​0-28-blahblah_post/b‌​lah.png
EDIT #2: After changing the directory names to "play nice" with Jekyll's regex, Jekyll no longer gives an error, but when I try to link to these images on my posts, they don't show up, unlike files in other non-_posts directories.
Jekyll won't process files not starting with the triple dashes block (frontmatter) so it is safe to have any other file in your _posts folder.
https://jekyllrb.com/docs/frontmatter/

html-minifier: Recursive but copying-over invalid files

I first met html-minifier today after running a small site I've created using Hugo through Google PageSpeed.
First thing I noticed is that although it does have recursion capabilities it stops working on unsupported files like images (my speakers started beeping and I freaked a little)
I've found this stack showing an apparently undocumented command-line option --file-ext
That worked perfectly but in the output directory, I noticed that the folders with the unmatching contents were gone.
From the directory root, I saw it was Hugo's folders for CSS, JS, images and Github Pages' CNAME file. Not only I can't tell for sure there's not even one piece of static file in any of the folders Hugo generated (you may know that Hugo is sometimes unpredictable) but also I would like to keep language specific XML Sitemaps I've created for some specific folders.
Long story short, is there a way to copy-over unmatching files "as is", keeping input directory ready for a commit/push?
After analyzing the whole directory structure I could be sure that within all the directory structure Hugo creates there are nothing more than HTML and XML files so then the Ockham's Razor took place.
Since both my Hugo's source code and output contents are in totally different directories, it was a simple matter of pointing the output directory to the same path of the input directory.
All HTML files are minified, overwriting those Hugo generated.

Jekyll -- create another folder with similar functionality of _posts

I have a _posts folder that contains all my posts for my blog and projects. I'd like to separate the markdown files for my blog notes and project pages. For example, in addition to the built-in md -> HTML conversion for files in _posts, I'd like to have a _projects folder that contain my markdown files for individual project write-ups and build them into HTML when running jekyll serve.
just define a collections key in your _config.yml:
collections:
projects:
output: true
Official docs for more info..
Looks like you want to use categories. Here is a link discussing a similar problem : Multiple _posts directories
By default Jekyll will ignore new folders with an underscore prefix, so you can't use _projects.
You can separate _posts in several folders, to have all your project files in a specific folder, create projects/_posts folder structure and move your project files inside projects/_posts, leaving blog posts in _posts.
Jekyll will generate each post and automatically assign the project category to them, so you can also generate different lists from your blog posts.