Integrate existing yaml file in a .md document - mkdocs

I am looking for a way to integrate an existing yaml file in a .md document. the yaml file resides in a gitub repo and can also be accessed relative to the .md file (for example ../dir/test.yaml)
I am using mkdocs for my site.

Use the mkdocs-include-markdown-plugin which is added using: pip install --no-cache-dir mkdocs-include-markdown-plugin
Then enable it in mkdocs.yml:
plugins:
- include-markdown
Now use:
Include relative text:
{% include "../test.yml" %}
Include relative markdown:
{% include-markdown "../README.md" %}
Read more about it under https://github.com/mondeja/mkdocs-include-markdown-plugin or see it on my examples https://alinex.gitlab.io/lang/mkdocs.html#include which are build using https://alinex.gitlab.io/docker-mkdocs/.

Related

HTML from _includes not showing where included using Jekyll

I'm hosting a personal site using GitHub Pages.
I'd like to reduce HTML code duplication by taking advantage of GitHub's builtin Jekyll templating functionality. For instance, putting footer.html into a /_includes directory for reuse on every future page.
I also happen to enjoy organising my files, so I put my 'real' index.html inside a /html sub-directory, along with all my other html files. GitHub pages doesn't like this, so I have used a dummy index.html in the root directory so that the site will be loaded by GitHub.
Whenever I use:
---
---
at the top of a .html file within my /html directory, they rather strangely get rendered as text at the top. In fact, so do my {% includes foo.html %} calls.
Why is this happening?
If you are using the 'dummy' index.html workaround, you will also need to enable Liquid in the root there by placing:
---
---
at the top of your dummy index.html:
index.html (dummy) <- double '---' here
html/
├─ index.html
├─ foo.html <- double '---' here to use {% includes bah.html %}
_includes/
├─ bah.html
This question helped the penny drop.

Jekyll Folder Structure. Having folders/lists on a page which each have specific posts

I have a page called blog.md which has some code like this.
permalink: /blog/
layout: collection
collection: blog
entries_layout: grid
classes: wide
Then I have a folder called _blog, with a number of .md files in.
Is there anyway I can add another level of order here and instead of displaying all the _blog .md files on the blog.md page.. I want to add two folders/lists which contain certain .md files.
Any ideas? Thanks
This should work by adding the path to your for loop. For example, let's assume you have a directory in your _blog directory called "orange." So your file path would be _blog/orange. To loop through only the files in the orange directory you could do this:
{% for post in site.blog.orange %}
{{ post.do-stuff }}
{% endfor %}
On a side note, Jekyll is going to look for blog posts in the _posts directory. I assume this _blog directory is a collection, but creating a "blog" collection will make things confusing if anyone else ever needs to touch this codebase.

cant publish my boostrap page on github page

I published my website on Github page. for the second time. But error appears which I don't understand. I used bootstrap for my page, here is the error
"Your site is having problems building: A file was included in
bootstrap-3.3.7/docs/components.html that is a symlink or does not
exist in your _includes directory. For more information, see
https://help.github.com/articles/page-build-failed-file-is-a-symlink/."
here is my github repository https://github.com/makopa/portfolio
I had a similar issue while deploying on GitHub an old website built in 2017 with Bulma. After updating all my dependencies, I still got the same error as Makopa. I deleted the /docs folder, redeployed with git status, add, commit and push and it worked!
That bootstrap-3.3.7/docs/components.html does indeed have include directives:
{% include components/glyphicons.html %}
{% include components/dropdowns.html %}
{% include components/button-groups.html %}
And the help page does mention:
Search for the include tag to see where you've referenced other files. For example: {% include cool_header.html %}.
Copy or move any symlinked files into the _includes directory of your GitHub Pages repository.
Maybe you could simply not include the doc folder of the bootstrap framework (so delete it) in your repo.

How to link on local filesystem with Jekyll?

I'd like to use Jekyll to share a page that cannot be served anywhere. I need to share this information using sync clients (Dropbox, Google Drive, WorkDocs, etc) and i'd like the links on the pages to work, regardless of the path where they are synced.
When i generate a new jekykll site with jekyll new somesite, then build with jekyll build, then open index.html from the filesystem, the links are broken because they are absolute.
For example, the href to the sample "Welcome to Jekyll" is generated as "/jekyll/update/2015/09/12/welcome-to-jekyll.html" and thus opens to "file:///jekyll/update/2015/09/12/welcome-to-jekyll.html" on my browser.
If it would generate us relative links, such as "jekyll/update/2015/09/12/welcome-to-jekyll.html", they would open fine regardless of the system or path they are opened from.
Would it be possible to change jekyll to use relative links instad of the default absolute links?
A fast and dirty way
If your page is in the root of the website (e.g. index.html), you could create relative links to posts using liquid filters, e.g.:
{% for post in site.posts %}
{{post.title}}
{% endfor %}
But, if you want relative links from every possible page in you site, I think that the only solution is to write a custom liquid filter that generate a relative link considering the current page location and the link location.
A clean way
Another (and more clean) way could be to use different _config.yml files for every destination. Here you can config each host and permalink structure to match the destination.
E.g. to serve your jekyll blog from http://example.com/my/subdir/blog:
# _config-example-com.yml
host: example.com
permalink: /my/subdir/blog/:year/:month/:title
Then build your blog using:
jekyll build --config _config-example-com.yml
If you have X targets, you could use a script to run jekyll X times (using every time a different config file) and then copy every output from _site to another directory, or upload directly where you want.

Jekyll : Using links to internal markdown files

md file with a link to Folder/file.md
When jekyll generates the index the link to the file is still folder/file.md and so doesn't connect to the generated file.html. Can jekyll replace links in markdown with their corresponding html files?
I really want to to maintain my folder structure (7 or so subfolders, each with 3 markdown files).
The answer since December 2016 is to use the jekyll-relative-links plugin.
It is a white-listed plugin if you are hosting on GitHub pages so you probably already have it.
If you are not using GitHub pages you will need the following installation instructions (from the README):
1.Add the following to your site's Gemfile:
gem 'jekyll-relative-links'
2.Add the following to your site's config file:
gems:
- jekyll-relative-links
The tag you're looking for is {% link %} and it arrived in 2016.
If you had {% link _funkyCollection/banjo.md %} it would generate the right path to the output file funkyCollection/banjo.html, or funkyCollection/banjo/index.html, or whatever, wherever it ends up being.
This is what I did to solve this problem with jekyll 3.8.5.
For link in root directory: /file.md
---
layout: page
title: Root File
permalink: /file/
---
This file is in root directory.
For link in subdirectory: /folder/file.md
---
layout: page
title: SubDir File
permalink: /folder/file/
---
This file is in sub-directory.
Now to link these file:
[Root File]({{site.baseurl}}/file/))
[Sub Dir File]({{site.baseurl}}/folder/file/)
Hope this helps someone.
i've written a simple plugin to solve this. put this in _plugins/, and make links refer to the *.md files (so github rendering linking works); if you build it with jekyll (when you are able to run plugins) the links are changed to *.html. since github doesn't run plugins, this isn't applied.
module ChangeLocalMdLinksToHtml
class Generator < Jekyll::Generator
def generate(site)
site.pages.each { |p| rewrite_links(site, p) }
end
def rewrite_links(site, page)
page.content = page.content.gsub(/(\[[^\]]*\]\([^:\)]*)\.md\)/, '\1.html)')
end
end
end
it's not perfect (i'm sure you could fool the regex) but it has been good enough for my purpose.
A Folder/file.md page will result in creation of a _site/Folder/file.html page.
So when your link to this page it's [Link to page]({{site.baseurl}}/Folder/file.html) not [Link to page]({{site.baseurl}}/Folder/file.md).
Jekyll will never rewrite file.md to file.html in url. So you have to set your links targets yourself to the resulting page.url which is usually a html file but can be css, je, json, ...
If you use permalink: /folder/folder/ in any file.md, it will generate a /folder/folder/index.html file which can be reached with [Link to page]({{site.baseurl}}/folder/folder/)
I've run into this and written a basic Jekyll/Kramdown plugin. It's less likely to break than the regular expression approach.
As long as your link doesn't start with http:// or something like it, and ends with .md, it will convert links to their lowercased and hyphenated names.
Of course, you could always modify the behavior to fit your needs.