How to recursively include only markdown in a directory in Jekyll - jekyll

I am putting the general project documentations together with some project source files and rendering that to gh-pages with Jekyll. For security reasons and building time optimization, I want to exclude everything inside my source directory except markdown files in Jekyll configuration.
I tried this in the _config.yml:
exclude:
- "src/*"
include:
- "src/**.md
but it doesn't seem to find the nested markdown. I wonder how should this properly get done.

Related

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.

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.

Keep Jekyll output files from permalink generation

I have one page - hello.html. For this page i have two languages which are defined in a config file. Also i have two different output directories configuration, different the original file name - en/ and pl/. Now, i can generate one lang by dedicated config, after this i can do this for second one.
My question is how to keep en/ directory when i'm generating pl/ one and reverse, how to prevent removing them form public output directory?
Using keep_files jekyll config feature is not working because output directory/file name is different then original.
Hope that this is clear enough.
If you don't mind having two config files, exclude the en files in your pl config, and vice versa. For example, in your pl _config.yml:
exclude: ["en"]
In your en _config.yml:
exclude: ["pl"]
From https://jekyllrb.com/docs/configuration/:
Exclude
Exclude directories and/or files from the conversion. These exclusions are relative to the site's source directory and cannot be outside the source directory.
exclude: [DIR, FILE, ...]

How to separate Jekyll posts into two different folders?

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