Image does not appear if in _posts/ directory - jekyll

Image does not appear in local host if saved in the _posts/ directory but appears if stored in another directory, e.g. posts/. Does anyone know why?
.md file:
![pressure plot]({{ site.baseurl }}/posts/fig/pressure-1.png) # appears
![pressure plot]({{ site.baseurl }}/_posts/fig/pressure-1.png) # doesnt appear
.html file from the .md file:
<img src="/my-awesome-site/posts/fig/pressure-1.png" alt="pressure plot" />
<img src="/my-awesome-site/_posts/fig/pressure-1.png" alt="pressure plot" />
config_yml:
baseurl: /my-awesome-site
Error message in Terminal after jekyll serve for _posts/:
ERROR `/my-awesome-site/_posts/fig/pressure-1.png' not found.
And the path in the error is actually correct (yes, the images can be found in _posts/fig/, I was testing things out by saving in different directories), but somehow the image just doesn't appear. Can anyone explain?
I dont think all these explain: OSF, OSF, OSF, Jekyll, unless I'm not understanding this whole thing.

Looking in Jekyll's documentation, _posts is one of the "reserved" directory, parsed by Jekyll for files named with the format YEAR-MONTH-DAY-title.MARKUP. Apart from the particular directories:
Every other directory and file except for those listed above [...] will be copied verbatim to the generated site.
So your image, while existing in your sources, will not be copied in the generated site (see the content of _site/), since it is in the directory _posts while not being named with the wanted format.

I ran into the same issue today. Turns out there's a useful plugin for resolving this issue called jekyll-postfiles!
Link to jekyll-postfiles
To install jekyll postiles, add the following to your GEMFILE:
source 'https://rubygems.org'
gem 'jekyll'
group :jekyll_plugins do
gem 'jekyll-postfiles'
end
Then run bundle. That's it!
Suppose you have the following structure:
_posts
|
|--> folder_a
|
|--> year-month-date-filename1.md
|--> picture.png
|
|--> folder_b
|
|--> year-month-date-filename2.md
|--> another_picture.ong
Then in filename1.md, you can invoke the image as:
<img src="picture1.png" width="700" height="500" class="center">
This is a very neat way instead of just putting pictures in a separate assets folder IMO.
Note: This plugin is not supported by Github Pages, host your site on services like https://netlify.com which support third party plugins.

Related

Jekyll custom placeholders

I am trying to set up a jekyll site that sources its pages from github repository. I can "bring" that repository using the git submodule command so that works just fine.
The URL I want to have is:
https://example.ld/:version/:language/:page-name
For the :page-name I can use the :title global placeholder.
My folder structure is:
posts
posts/1.0
posts/1.0/en
posts/1.0/en/about.md
....
posts/1.0/fr
posts/1.0/fr/about.md
....
I tried playing around with the permalink option in the configuration but cannot find the right combination to do what I need since :language of course does not exist as a placeholder or does :version.
Is there a way to define those so that my users can visit the site and view https://example.ld/1.0/en/about?
Should I move the docs folder under the _posts folder?
Any pointers are more than appreciated. Thank you.

Mkdocs site is opened incorrectly

I've got mkdocs.yml file which looks like:
site_name: blabla
pages:
- One page: page2.md
- Second page: page2.md
- Navigation: Navigation.md
When I open it url is like this: http://10.2.0.8/blabla/master/Navigation.md and doesn't work and I get 404 Not Found
nginx/1.14.0 (Ubuntu) error. If I delete .md at the end of url it works fine.
However, on locally it opens like http://127.0.0.1:8000/Navigation/
does anyone know what's the problem with this?
As described in the official mkdocs documentation, the intended behavior is that http://10.2.0.8/blabla/master/Navigation.md does not exist, but rather http://10.2.0.8/blabla/master/Navigation as shortcut for http://10.2.0.8/blabla/master/Navigation/.
What might have gone wrong in your case is the deployment of the HTML & CSS files. Assuming that your markdown sources are in ~/blabla, a mkdocs build --clean within that directory will create a subdirectory ~/blabla/site/ which you then have to deploy in the respective directory, say /var/www/html/blabla/. Under Linux, I suggest a rsync -r --delete-before ~/blabla/site/* /var/www/html/blabbla/. In other words: The issue might also be that you simply have not deployed the whole site or at a different place.

Where to find default layouts in Jekyll

The default site setup for a new Jekyll site has a layout specified as "home" in index.md:
---
# You don't need to edit this file, it's empty on purpose.
# Edit theme's home layout instead if you wanna make some changes
# See: https://jekyllrb.com/docs/themes/#overriding-theme-defaults
layout: home
---
If I follow the link, it tells me to create a _layouts folder and create a file in it named home.html and that will be used as the home layout. But if that file doesn't exist Jekyll defaults back to the normal home page.
Where is Jekyll pulling the default layout from?
This default layout comes from the theme, which is gem based and is stored on your computer.
To locate a theme’s files on your computer:
Run bundle show followed by the name of the theme’s gem, e.g., bundle show minima for Jekyll’s default theme. This returns the location of the gem-based theme files. For example, the Minima theme’s files might be located in /usr/local/lib/ruby/gems/2.3.0/gems/minima-2.1.0 on macOS.
Source
I would suggest to start without a theme. Invisible files do not really help you to understand an already quite abstract concept. Remove the theme and write your own layouts and CSS. When you get how it works, you also truly understand how a theme works and what it can and cannot do.
Removing the standard (or any other) theme is simple. Just go to the _config.yml file and remove theme: minima. Now you will use only visible files. You might also want to remove the 'Gemfile', but that requires you to also remove the 'jekyll-feed' plugin from the config. No problem, as you can easily roll your own: https://jekyllcodex.org/without-plugin/rss-feed/
From this version of the manual:
Run bundle info --path followed by the name of the theme's gem, e.g., bundle info --path minima for Jekyll's default theme.
The layout files will be in the _layouts sub-directory of the path returned by the command above.

add subfolders to _includes directory in Jekyll

I'm trying to add folders inside the "_includes" directory on Jekyll. It doesn't work. I've tried adding an underscore to the folder but it doesn't work either. What am I doing wrong? I'm using Jekyll 3.7.0
The most useful link I found about it was this one
Here are some screenshots:
And the stacktrace is:
Incremental build: disabled. Enable with --incremental
Generating...
Pagination: Pagination is enabled, but I couldn't find an index.html page to use as the pagination template. Skipping pagination.
Liquid Exception: Could not locate the included file 'sidebar.html' in any of [".../_includes"]. Ensure it exists in one of those directories and, if it is a symlink, does not point outside your site source. in /_layouts/page.html
jekyll 3.7.0 | Error: Could not locate the included file 'sidebar.html' in any of [".../_includes"]. Ensure it exists in one of those directories and, if it is a symlink, does not point outside your site source.
I think I'm supposed to be able to use sub-directories. What am I doing wrong? Thank you in advance!
Apparently, I found the problem. I don't know why but Jekyll is somehow able to parse comments. It detected I had commented a piece of code referencing the old sidebar.html.
As #DavidJaquel mentions in a comment below, HTML comments <!-- --> are not stopping Liquid to parse our page content, so we should be using Liquid syntax:
{% comment %}
...
{% endcomment %}

how to access assets/images from the view in Sails.js?

I simply want to add an image in a view in my Sails-Project
My view-file has the location
views/album/albums.ejs
and the image is located in
assets/images/placeholder.png
if I add the image like this
<img src="../../assets/images/placeholder.png">
I get this error
GET http://localhost:1337/assets/images/placeholder.png 404 (Not Found)
Am I missing something?
Sails use Grunt (Gruntfile.js in root of project) to execute some tasks during sails lift. One of that tasks is to copy files from assets directory to .tmp/public/ directory (in development version). So if u add your file to assets directory you will need to restart sails (sails lift) to get it accessible from .tmp/public/ (what is public accessible directory root). Also its important to note that if u put files directly to .tmp/public/ it will be accessible instant, but on next sails lift it will be deleted, since one of Grunt tasks is to clear that directory before copy new files. All of this u can find on sails documentation (assets and asset-management) and by reading Gruntfile.js in root of your project
<img src="/images/placeholder.png">
should work. the assets folder is the equivalent to adding a folder with the static middleware in express.
asset documentation
Looks like you have grunt hook removed.
When removing the grunt hook you must also specify the following in .sailsrc in order for your assets to be served, otherwise all assets will return a 404.
{
"paths": {
"public": "assets"
}
}
I was also facing the same problem.
In sails version 0.12.0,
I was trying to show an image from assets folder to homepage.ejs.
Then by using below img tag, it solved my problem.
<img src="/images/placeholder.png" width="30px" height="30px">
But as your ejs file is inside views/album/albums.ejs
I may suggest, below may work
<img src="../images/placeholder.png" width="30px" height="30px">
But the right approach in sails ejs pages is,
<img src="/images/placeholder.png" width="30px" height="30px">
This must work for you also.
If you have the tasks/sync.js file in your project, add the following object in files array:
{
cwd: './assets/images',
src: ['**/*.*'],
dest: '.tmp/public/images'
}
you need to have sails-hook-grunt and grunt-sync installed.