travis-ci : error during the build (No such file or directory) - jekyll

I'm having a problem trying to test my build on travis-ci for my jekyll app. One of the plugins generates a json containing informations that my app can reach for a search tool.
The build command works fine on my computer :
bundle exec jekyll build --source octopress
Witch indexes informations into a search.json file in my built directory (_site).
But it fails on travis-ci as on Heroku.
writting search.json to /home/travis/build/alain-andre/mon_site/_site
jekyll 2.5.3 | Error: No such file or directory - /home/travis/build/alain-andre/mon_site/_site/search.json
Can anyone help ?

OK, I found the solution.
I had to add the search.json into the jekyll site.keep_files.
First to do is to create a Jekyll::StaticFile inside your Jekyll module.
class SearchJson < Jekyll::StaticFile
def write(dest)
begin
super(dest)
rescue
end
true
end
end
Then, when your file is created, add it to site.static_files like this :
# Keep the file from being cleaned by Jekyll
Jekyll::SearchJson.new(site, site.dest, "/", filename)
site.keep_files << filename

Related

Is there a directory that will place items in the root of _site on build?

I have a bunch of static files (basically favicons, apple-site-icons, etc) that I want to be at the root of _site when it's built. Currently they're just sitting at the root of my main code folder (along with _posts, _scss, _layouts, etc). It builds fine but it would be nice to move them into a subdirectory so the main directory isn't cluttered up (it's an OCD thing).
Is there any folder where I can put these items so they automatically copy to the root of _site when I build? I know I can write a script to do this and trigger it after the build, and there's probably an extension I could lean on, but I'm looking for a solution that just automatically moves them when I run jekyll build for simplicity.
NBD if I can't do it, just curious because I'm kind of a neat freak.
Thanks!
Jekyll allows you to do exactly that using permalinks.
Permalinks are the output path for your pages, posts, or collections. They allow you to structure the directories of your source code different from the directories in your output.
A simple example extracted from the official page is a case where you have /my-pages/about-me.html with the front matter as follows:
---
permalink: /about/
---
This way you specify the output url. In this example, you could access it in local with localhost:4000/about/
The source option. You can specify this in your _config.yml or as a command line option (https://jekyllrb.com/docs/configuration/options/). How you set this has slightly different requirements/implications.
First, move everything that belongs to the Jekyll site into a folder (e.g. "src").
Then set one of these up (assuming you have a Gemfile):
Command line option with root Gemfile:
Keep Gemfile in the root folder
Run bundle install
Run bundle exec jekyll serve --source src
Command line option with nested Gemfile:
Run BUNDLE_GEMFILE=src/Gemfile bundle install
Run BUNDLE_GEMFILE=src/Gemfile bundle exec jekyll serve --source src
Config file option:
Keep Gemfile and _config.yml in the root folder
Add source: src somewhere in your _config.yml
Run bundle install
Run bundle exec jekyll serve
Each solution here might work better with other external services building your site. There are likely other ways to set this up, but this should get you started.

Why isn't there a "jekyll post" command to create posts like in hexo?

Do I have to manually create markdown files? Can't jekyll generate a post/draft file with YAML parameters included and YYYY-MM-DD-title filename format?
Did I miss something?
You can use jekyll-compose.
It's a command line utility to help you with your workflow. Install it with:
gem 'jekyll-compose', group: [:jekyll_plugins]
bundle
Then you create pages, blogs etc like this:
$ bundle exec jekyll post "My New Post"
Please see the link above for full reference.

Jekyll not finding blog posts

Source Code
I am new to Jekyll and got it installed with Grunt and SASS. My issues is that while my test site will show my new posts, When I click on the post link I get an error "Cannot GET /blog/example-post-name".
Grunt doesn't show any errors when running Grunt Serve. However if I run Jekyll serve I get the following errors:
Build Warning: Layout 'article' requested in app/_posts/2015-01-31-optimized-jekyll-site-with-grunt.markdown does not exist.
Build Warning: Layout 'article' requested in app/_posts/2017-03-20-welcome-to-jekyll.markdown does not exist.
Liquid Exception: Could not locate the included file 'blog.html' in any of ["/Users/rich/jekyll-site/_includes"]. Ensure it exists in one of those directories and, if it is a symlink, does not point outside your site source. in app/index.html
jekyll 3.4.2 | Error: Could not locate the included file 'blog.html' in any of ["/Users/rich/jekyll-site/_includes"]. Ensure it exists in one of those directories and, if it is a symlink, does not point outside your site source.
It appears that it cannot find anything in my: _includes, _layouts, ect... folders.
Any help would be appreciated.
Since your template files are in the app/ directory, simply build with app as the source directory.
Add the following to your _config.yml:
source: app
Then run jekyll serve as usual.
Try adding blog.html file in _includes folder or use layout: default in your posts 2015-01-31-optimized-jekyll-site-with-grunt.markdown etc.

gh-pages with static html can't access file when it exists

The index.html home page displays fine, however any any link will throw a 404.
The static website has folder with html in it, index link to these html with the correct path, but displays a 404.
When clicking on this link, I got a 404.
however the file is present as you can see here .
I am really banging my head on a simple html pb, which is frustrating.
I ran into this problem myself and finally discovered a simpler solution. The problem is that Jekyll ignores all files that start with _. The simple solution is to add a .nojekyll file to your docs dir.
My docs script looks like this:
"rimraf ./docs && typedoc src/ --out docs --mode modules --module commonjs --target es6 --excludePrivate && touch ./docs/.nojekyll && gh-pages -d docs -t"
touch is an npm module that creates the file and the -t flag on gh-pages is necessary to have that dot file uploaded.
Alright I though I might just answer my own question here.
Github Page doesn't allow several static HTML files.
This is not very clear to be honest on their docs, but the solution is quite simple :
Assuming your local static docs works correctly, just follow these steps :
install jekyll
gem install jekyll bundler
add a file _config.yml
in your docs or on the root of your gh-pages branch with this content:
auto: true
execute jekyll serve
And test if this works ok on the url outputed in your console
add _site in your .gitignore
push and bingo!
If you are like me using typedoc to compile typescript into nice documentation, you will run into trouble.
Because Jekyll automatically exclude from the build any files starting with _, and typedoc generates ONLY that, I wrote a simple yeoman generator that does all the replacement for you.

Adding Jekyll to an existing website

I have a simple website and tried to add a Jekyll blog in it in a new folder blog thus I have run jekyll new blog in the folder /path. However when I'm running the command jekyll build in /path I have these errors:
$ jekyll build
Configuration file: none
Source: /path
Destination: /path/_site
Generating...
Build Warning: Layout 'post' requested in blog/_posts/2015-06-14-welcome-to-jekyll.markdown does not exist.
Build Warning: Layout 'default' requested in blog/index.html does not exist.
Conversion error: Jekyll::Converters::Scss encountered an error converting 'blog/css/main.scss'.
Conversion error: File to import not found or unreadable: /blog/_sass/base.scss. Load paths: on line 47
I solved the first problem (Configuration file: none) by moving _config.ymlin the parent folder, however I still have problems when requesting layout using
---
layout: default
---
The imports in main.scssare also not working (last error).
If I'm doing the same command jekyll build in /path/blogafter moving again _config.yml, I have no errors. Does someone know how to be able to do a jekyll buildin the parent folder with the configuration I have? Do I have to entirely change the architecture of my website to include a Jekyll blog in it?
You config.yml is in /path with
source: /_jekyll
destination: /blog
baseurl: /blog
Your jekyll sources are in /path/_jekyll.
And you generated files will be in /path/blog.
Ready to deploy !