Confused with paths running jekyll website locally - jekyll

I host my website on GitHub Pages so I used site.github.url in my URL's (as it is described in documentation). Like this:
{{ page.title }}
in documentation it is also said that
This way you can preview your site locally from the site root on localhost, but when GitHub generates your pages from the gh-pages branch all the URLs will resolve properly.
Now I try to preview it locally, but all the links have http://my-username.github.io/ in front of them.
What am I doing wrong? Maybe I am missing something?

Locally you can use a _config_local.yml to override default URL value.
Add this in your _config_local.yml:
github:
url: http://localhost:4000
And then you can launch Jekyll and ask to parse both config files like this:
bundle exec jekyll build --config _config.yml, _config_local.yml
and
bundle exec jekyll serve --config _config.yml,_config_local.yml
Optional: You can alias the command or use rake to launch tasks.
Add the rake gem to your Gemfile:
group :development do
gem 'rake'
end
Install with bundle install
Create a Rakefile:
touch Rakefile
Copy this content in your Rakefile:
require 'jekyll'
task :build do
options = {
'trace' => true,
'verbose' => true,
'config' => %w(_config.yml _config_local.yml)
}
Jekyll::Commands::Build.process(options)
end
task :serve do
options = {
'serving' => true,
'watch' => true,
'incremental' => true,
'config' => %w(_config.yml _config_local.yml)
}
Jekyll::Commands::Build.process(options)
Jekyll::Commands::Serve.process(options)
end
Now you can use bundle exec rake build and bundle exec rake serve without having to pass options.

Related

Unable to minify Jekyll javascript via jekyll-assets or jekyll-minifier

I'm having a heck of a time figuring out how to get Jekyll (v4.0.0) to minify javascript. I have installed jekyll-assets (v3.0.12) and jekyll-minifier (v0.1.10) in an effort to do so, but no luck so far... the javascript remains unminified.
I've tried a number of configuration options in _config.yml that didn't help, referencing the documentation here:
https://github.com/envygeeks/jekyll-assets/tree/v3.0-current#configuration
Any help would be greatly appreciated!
Gemfile
# frozen_string_literal: true
source "https://rubygems.org"
git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
# gem "rails"
gem "jekyll", "~> 4.0"
group :jekyll_plugins do
gem "jekyll-assets"
gem "jekyll-minifier"
end
_config.yml
permalink: pretty
sass:
style: compressed
exclude:
- gulpfile.js
- node_modules
- CNAME
- README
- '*.json'
- .DS_Store
plugins:
- jekyll-assets
- jekyll-minifier
assets:
sources:
- "css"
- "js"
_includes/scripts.html
...
{% javascript app %}
...
js/app.js
//=require scripts.js
//=require scripts-2.js
var myStr = "app";
myStr += " js";
console.log(myStr);
command line
JEKYLL_ENV=production bundle exec jekyll build
The Jekyll-Minifier plugin may be minifying javascript in the _site directory after Jekyll creates the static site. If you are using github pages, this won't work as Github is building from the source and has limited plugin support. You may have to build using the plugin and use the _site directory to serve manually, or find a different plugin that minimizes in place rather than in the _site directory.

Jekyll ignores second configuration file

I’ve created two config files on the root of my site _config.yml and _production.yml.
I’m using NPM to build my site using the following script:
"scripts": {
"build": "JEKYLL_ENV=production jekyll clean && jekyll build --config _config.yml, _production.yml"
},
But the second file, where i overwrite the Sass output style get’s ignored.
Same result when using bundle exec.
I’m using jekyll 3.8.6, node v10.15.0, npm 6.10.2, ruby 2.3.7p456
Any ideas on this ?
You can have a look here GitHub, 7766 or on stackoverflow.
Solution a) skip the space between the comma separated list
jekyll build --config _config.yml,_production.yml
Solution b) wrap the config file list with quotes
jekyll build --config "_config.yml, _production.yml"

Jekyll custom theme (running locally)

I'm new to Jekyll and I am trying to get a custom theme up and running. Here's is what I've done so far:
Created my Jekyll site. CD to the directory I wanted to install it and ran
bundle exec jekyll serve
These files were created and I was able to see the site locally at the default 4000 port.
I then tried following the instructions here for installing your own theme. I entered this in my terminal:
$ jekyll new-theme skull_and_roses
As the instructions indicated it built out a new directory...
It also added a directory in the _site directory, not sure if that is correct:
I then followed these instructions:
But when I go to run it:
bundle exec jekyll serve --watch
I get an error:
The skull_and_roses theme could not be found.
Like I said, this is my first run at Jekyll so any help would be appreciated.
I also use jekyll theme template (It is a nice template with friendly manual) and customize it to set up my own github page recently.
Beside create repo on github use username (username.github.io), What I did on my mac (locally) are:
set up env for using Jekyll, you can reference: https://jekyllrb.com/docs/
$ git clone https://github.com/username/username.github.io.git (assuming you have already create the repo).
$ cd username.github.io
$ git clone <theme github repo>
put all the theme files into the root of your website files (dir we create in step2)
usually the theme template will have Gemfile, if really not, you can try to create Gemfile and type in:
source 'https://rubygems.org'
gem 'github-pages', group: :jekyll_plugins
After you confirm you have Gemfile, Run
$ bundle install
$ bundle exec jekyll serve
Now, you can enter localhost:4000 or 127.0.0.1:4000 to check the theme can run on local serve.
Then you can mainly modify _config.yml file, like title, author, and other from the theme template instructions. You can check it locally(localhost:4000 or 127.0.0.1:4000) whenever you update something and you want to check the result. Usually changing in _config.yml, you need to restart the jekyll serve (using ctrl+c to stop and run $ bundle exec jekyll serve to restart the service to check the modification. You may need to modify more than _config.yml file to meet your own requirement, at least like about.md or add your own posts in _post.
After you finish modification from theme template and make your own github page you like. You can push the local repo to remote repo (master branch of username.github.io). Btw, if you work locally, you can use branch to test features you want to add, checking result locally and then merge to master when you are satisfied with the result.
Finally, you can check: https://username.github.io and enjoy your own github page.
For your question about _site and other things you may want to know, you may also want to check followings:
Creating and Hosting a Personal Site on GitHub
Quick start & tutorials on jekyll

Run jekyll build Command with Different url Flag

My current _config.yml file looks like this:
#Site settings
...
baseurl: "" # the subpath of your site, e.g. /blog/
url: "http://10.0.1.9:3000" # the base hostname & protocol for your site
...
# Build settings
markdown: kramdown
safe: true
lsi: false
highlighter: true
keep_files: [public]
exclude: [src, lib, node_modules, bower.json, Gemfile, gulpfile.js, package.json, README.md]
I've got my url currently set to my local server, where I serve my Jekyll site for local development.
When building for production however, I have to keep manually changing this url to the url of my remote server before running jekyll build. Is there a way I can pass my remote url alongside the jekyll build command to build a site with the correct remote paths?
Something like so:
jekyll build --url mysite.com
Any help is appreciated with this. Thanks in advance!
Put your production url in _config.yml eg: url: toto.com.
Create a _config_dev.yml that will be used to override values in development.
In you case
url: "http://10.0.1.9:3000"
Development build is launched with :
jekyll build --config _config.yml,_config_dev.yml
Values in the last config file in the command will override those in first file.
and production build with jekyll build.
See Jekyll documentation http://jekyllrb.com/docs/configuration/#build-command-options configuration paragraphe.

Jekyll chef recipe

In some ways, it's the getting started with chef problem. But, I'm trying to create a simple recipe to checkout from github my jekyll code then run jekyll to build it locally. I've not started worrying about getting the nginx configuration running, but I've tried just about 100 different permutations of the 'before_migrate' script and have yet to find a way to load jekyll into either a gem that's available or into the path to do an command "jekyll ..."
Here is the current recipe as it stands:
include_recipe "git"
application "corpsite" do
path "/opt/tubularlabs/corpsite"
repository "git#github.com:Tubular/corpsite.git"
revision "master"
deploy_key <<EOF
-----BEGIN RSA PRIVATE KEY-----
...
-----END RSA PRIVATE KEY-----
EOF
before_migrate do
execute 'Deploy Jekyll blog' do
chef_gem "jekyll" do
action :install
end
require "jekyll"
command "jekyll"
action :run
end
end
end
UPDATE:
The problem turned out not to be a recipe issue at all, but rather that one of the HTML docs contained a UTF-8 charactered and jekyll was running with LC_ALL=C thus barfing. It didn't help that this was of course the first recipe I ever tried to write.
For historical sake, heres' the final script
before_migrate do
chef_gem "jekyll"
execute 'Deploy Jekyll blog' do
cwd release_path
environment ({"LC_ALL" => "en_US.UTF-8"})
command "jekyll"
end
end
I've installed gems and required them before like this
gem_package "nokogiri" do
action :nothing
end.run_action(:install)
gem 'nokogiri'
require 'nokogiri'
Hopefully that works out for you (tried it with jekyll and works)