Folder _data in theme directory does not get the values - yaml

I'm making a Jekyll theme using the command jekyll new-theme mytheme. I want to add translations to this theme, so I created the file _data/translations.yml into the root directory. This is its content:
---
en:
post: "Post"
es:
post: "Artículo"
I get the information with this expressions:
{% assign t = site.data.translations %}
{{ t[site.lang]['post'] }}
This setup only works if I move the _data/translations.yml file to my Jekyll website directory, created through the command jekyll new mysite.
Are the data files out of themes territory? Should I place this yml file in another directory? If it's not possible to use it in the themes territory, I would like to set a default value: how can I achieve this?
Thanks in advance.

As of Jekyll 4.0, yes, data files inside a theme-gem are not read.
You'll need to use a plugin named jekyll-data (authored by me).
If you plan to publish the theme for other users, I recommend adding the plugin as a runtime dependency in the theme's gemspec. Otherwise, simply adding the plugin to the :jekyll_plugins group in the site's Gemfile will suffice.

Related

module files not downloading for themes

I want to change my site using Hugo. I get stuck with modules. As per documentation (e.g. this theme) I just add theme = "github.com/nodejh/hugo-theme-mini" to the config file. It fails like this:
WARN ... found no layout file for "HTML" for kind "term": You should ...
if I perform hugo mod vendor the directory structure of the theme seems created in the _vendor dir, but there is not a single file inside. which explains the "not found" error in my eyes.
nothing (!) is rendered.
I also have this effect with a couple of other themes (I thinknoteworthy being one of them).
Set up a clean project
hugo new site testModules
cd testModules
and enable Hugo modules
hugo mod init randomName`
Paste the following lines in config.toml:
baseURL = "http://example.org/"
title = "Hugo Modules Test"
[module]
[[module.imports]]
path = "github.com/nodejh/hugo-theme-mini"
Start Hugo
hugo serve -D
Done!
The content of github.com/nodejh/hugo-theme-mini" will be downloaded and used as theme.
See the theme's documentation to add content
Optional:
hugo mod vendor
will make the content of the remote repo available in the _vendor folder.
(Surprisingly the content of exampleSite was not downloaded during the quick test I made)

Jekyll blog error: Could not locate the included file 'file.ext' in any "_includes"

I'm a newbie to use jekyll as github blog page creater. now i try to write a md file under _posts folder, i copy the text and layout from Jekyll Docs, due to it contains some Liquid syntax(showed above).
When i run Jekyll in local, the below error is showed.
Liquid Exception: Could not locate the included file 'file.ext' in any of
["C:/Developments/GitRepository/testRepository/blogFork1/_includes"].
Ensure it exists in one of those directories and, if it is a symlink,
does not point outside your site source.
in C:/Developments/blogFork1/_posts/2018-08-03-first-blog.md
What i write in md file:
How can I treat those statement as general statement? Thanks for anyone's help!
The error says that you're trying to include file.ext in your post. I don't think you need this. If you do, you must create a file named file.ext in root/_includes. But as I said, I don't think you need this file as the docs are simply telling you how to include a file of any extension in a post. Just remove {% include file.ext %} from you post.

Setting multiple categories in jekyll

I have a markdown file as follows:
---
title: My Page
categories:
- first
- second
---
In my _config.yml file, I set the permalink to /:categories/:title.html
So when I generate the site, the permalink ends up being /first/second/title.html, whereas
I was hoping Jekyll would create /first/title.html and /second/title.html
Is there a way to do this without custom plugins?
Cheers
The easiest and to me best way is to define the permalink via frontmatter. This is also great for search engine optimization. First you tell Jekyll via _config.yml how Jekyll should build the links if you forget to set it via frontmatter:
_config.yml
# Build settings
permalink: /:categories/:title/
Define a permalink...
2014-10-17_my_post.md
---
layout: post
title: 'Post with permalink'
permalink: /this-is-the-unique-permalink/
---
My Post
According to these docs, it looks like each Jekyll page can only have one category. categories is kind of a misnomer, because you're really defining a "category hierarchy" - like a file path - so the post really resides in a single (sub)category. In this limited sense, you can't do what you want with vanilla Jekyll.
However, Jekyll will process files just sitting around in any directory that doesn't start with an underscore and it follows symlinks. So, for example, if you make directories for each category and place your page in one of them, you can create symlinks to any number of other "categories".
mkdir first second
touch first/page.md
ln -s ../first/page.md second/

Generated markdown file with rake post command

I am deploying my github blog using jekyll-bootstrap.I try to modify Rakefile to change the result of $rake post title="test" and then this command will generate a file named test.md(without date) in _posts directory,but unfortunately,when I run
$jekyll serve
locally,it seems that jekyll do not think test.md is an available post,what shoul I do?
I think that what you want it's custom url for your posts.
Leave alone the rake task, because the final post filename is generated in accordance with a permalinks pattern see permalinks documentation
By default you posts are generated following the default pattern /:categories/:year/:month/:day/:title/index.html
If you want to change this pattern, in your _config.yml, use permalink key :
permalink: /blog/:year/:month/:day/:title/filename.html

How can I debug plugins that are being silently ignored?

Newcomer to Jekyll here (previously on Hyde).
Ruby files placed in the _plugins/ directory are apparently silently ignored.
I am using version 0.11.2 of Jekyll, with ruby 1.8.7 on Ubuntu 12.04.
Should an extra config parameter be added to load these plugins? The doc doesn't say so - the sane default should be to look into _plugins, and they should be required automatically. How can one debug the loading of Jekyll plugins?
For my instance of jekyll (also 0.11.2, but with ruby 1.9.2p290 on a Mac), I don't have to add any extra configuration, but you can try adding the following line to your top level "_config.yml" file.
plugins: _plugins
or, possibly,
plugins: ./_plugins
The simplest way to test that your plugins are working is to remove all of them except for one that you know will work. I've put together the following which works as expected on my install.
Create a new file in the root of your jekyll source directory called "plugin_test.md" with the following contents:
---
layout: default
title: Plugin Test
---
the quick brown fox jumps over the lazy dog.
Testing plugin output of '_plugins/testplugin.rb': {% testplugin %}
Note that you may need to change "layout: default" to whatever you are actually using.
Create a new file at "_plugins/testplugin.rb" with the following contents:
module Jekyll
class TestPlugin < Liquid::Tag
def render(context)
"It's Working!"
end
end
end
Liquid::Template.register_tag('testplugin', Jekyll::TestPlugin)
Run jekyll on your source dir.
All that testplugin.rb does is replace instances of the liquid tag {% testplugin %} with the text "It's Working!". If your plugins are triggering, you'll see the output
Testing plugin output of '_plugins/testplugin.rb': It's Working!"
on the page "plugin_test.html" at your output site root. If you see:
Testing plugin output of '_plugins/testplugin.rb':
that means that the plugin didn't trigger. If you run into that, I think it's a sign that something is pretty out of whack and would advise reinstalling jekyll.
I know I'm little bit late but for others who still come across this question I would like to add my resolution:
Restart the server to get the newly added plugin working. So stop jekyll serve (Ctrl C) and restart it again with jekyll serve.

Resources