jekyll not generating _posts - ruby

I'm have trouble getting jekyll to convert a post in _posts directory to html. It generates index.md correctly, but doesn't generate anything for posts. When I add 'source: _posts' then it converts the post, but doesn't convert index.md.
As far as I can tell, 'source' should either be not added to _config.yml to should point to '.'
My directory structure is pretty standard:
$ find .|fgrep -v bootstrap
.
./index.md
./_config.yml
./_drafts
./_includes
./_includes/footer.html
./_includes/header.html
./_layouts
./_layouts/default.html
./_posts
./_posts/2013--02-25-test-blog.md
./_site
./_site/index.html
$ cat _config.yml
name: "Developer blog"
description: ""
url: "http://localhost:4000"
source: .
paginate: 10
markdown: rdiscount
permalink: pretty
pygments: true
auto: true
Even when I leave auto off, I see no stack traces.
$ cat _posts/2013--02-25-test-blog.md
---
layout: default
title: Testing a blog
---
#test blog
this is a test

_posts/2013--02-25-test-blog.md
This name is not correct.
Perhaps use this
_posts/2013-02-25-test-blog.md
Notice carefully only 1 hyphen after the year.

Related

How do I get amsmath to work in RMarkdown when knitting to PDF?

In RMarkdown, I have a document I want to knit to pdf. The document has equations for which I need automatic numbering. I had been using the $$ 1+1=2 \tag{1} $$ convention to write equations, but now want to switch to the \begin{equation} 1+1=2 \eq:this_eq \end{equation} convention so that I can have automatic numbering and easy cross referencing of the equations. The few online resources I've found make it seem like this should be fairly straightforward to do. For example here or here. However, I have run into no end of heartbreak in attempting to do it.
I am using version 3.4.3 with RStudio, the tinytex distribution, and have installed bookdown (which I am still not sure is really necessary to achieve my goal here). Here is a repex:
---
title: This title
author: "This guy"
date: "This date"
header-includes:
- \usepackage{amsmath}
output:
pdf_document:
toc: yes
toc_depth: '4'
df_print: kable
fig_caption: yes
latex_engine: xelatex
mainfont: Calibri Light
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```
## Introduction
blah blah...
\begin{equation}
S = X \bar{P}
(\#eq:signals)
\end{equation}
## Later on
blah blah \#ref(eq:signals)
When I try to "knit to PDF" I am running into the error
! Package mathspec Error: `amsmath' must be loaded earlier than `mathspec'.
which has been reported as a bug and "fixed" here, but I am unable to understand the fix or to follow its instructions. What I'm asking for is a set of really clear steps that will get me to where I can run the repex above without incident.
Some things I've tried:
The same error occurs when I replace pdf_document with bookdown::pdf_document2. Or when I remove
header-includes:
- \usepackage{amsmath}
and instead put
includes:
in_header: preamble.tex
after the line latex_engine: xelatex, where "preamble.tex" is a notepad file containing the line \usepackage{amsmath}
The comments in this other SO post seem to suggest that it is not even necessary to say anything about amsmath in the YAML options, which confuses me even more. When I remove any mention of amsmath from the YAML options, I get errors saying that the mathjax script is not recognized, for example:
! Package amsmath Error: \bar allowed only in math mode.
When I try your example, the equation is not labelled successfully.
Then I replace the output setting as bookdown::pdf_book. It works.
---
title: This title
author: "This guy"
date: "This date"
output:
bookdown::pdf_book
mainfont: Calibri Light
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE)
```
## Introduction
blah blah...
\begin{equation}
S = X \bar{P}
(\#eq:signals)
\end{equation}
## Later on
blah blah \#ref(eq:signals)
For my problem, the solution came down to me just changing my latex engine from xelatex to lualatex. My document knit correctly and numbered my equations. For some reason, everywhere I looked they say one should use xelatex. Also I had header-includes: - \usepackage{amsmath} in the YAML header.
I was facing this issue. Thanks for the suggestions above. Here is what worked for me in the output and header-includes parts of the preamble:
output:
bookdown::pdf_book:
latex_engine: lualatex
header-includes:
- \usepackage{amsmath}

Explain to me a Sinatra setup for dummy's for a preview of html/css code

A word of warning up front: I do not know even the ruby basics, but I'm trying to learn more and more of the world of shell scripting this year.
I saw this Vimeo video of Ben Schwarz and immediately thought that I'd like to use such a tool to debug my sass and haml files.
So this is a call to help me to grasp the concept of Sinatra.
What I want is a simple way to output the code of my index.html to check if all the haml magic was applied correctly - so it should function as a source viewer that gives me live updates. I'd prefer it if Sinatra simply looked at the files that LiveReload already rendered (c.f. index.html) in my project folder.
Update: This is a screenshot of the Vimeo Video. It shows just the raw CSS output of a Sass file. This is what I'd like to have for my Haml and Sass code, or better for the output files that are already rendered by LiveReload as HTML and CSS.
I looked at the source file from #benschwarz at his github, but I wasn't even with his own example I'm only getting the standard: "Sinatra doesn’t know this ditty." So transferring this to work with html is still out of my reach.
What I did so far:
I setup my project as usual in ~/Sites/projectname
I setup RVM and install all the gems I need
Sass, Compass, Haml - the output gets compiled via LiveReload
Sinatra
I created myapp.rb in ~/Sites/projectname with the following content:
# myapp.rb
require 'sinatra'
set :public_folder, '/'
get '/' do
File.read(File.join('public', 'index.html'))
end
Whatever, I fired up Sinatra and checked http://localhost:4567/ – this didn't work because I do not know how to set the public_folder to ~/Sites/projectname.
Afterthoughts:
So I went on to search the net, but my limited knowledge of Ruby put my attempt of an successful research to an immediate halt.
Here are some sites I stumpled upon which are obvioulsy close to the solution I need, but… like I told you in the first sentence: if the solution was a book, I'd need the "For Dummies" version.
https://bitbucket.org/sulab/genelist_store/src/30fc0ba390b9/idea8/idea8.rb
Serving static files with Sinatra
http://www.sinatrarb.com/intro
Obvioulsy the reference documentation of Sinatra would help me, but I don't speak the language, hence, I don't get the lingo.
About public folder:
The public_folder is relative to your app file myapp.rb. If you have a public folder inside the projectname folder, this is your public folder. If you have your css, js and image files in another folder, say, includes under project_name, then you need to change the line:
# Actually, you need to remove the line above from myapp.rb as it is.
# The line means that the public folder which is used to have css, js and
# image files under '/' and that means that even myapp.rb is visible to everyone.
set :public_folder, '/'
# to:
set :public_folder, File.dirname(__FILE__) + '/includes'
And that will serve up css, js and/or image files from the project_name/includes folder instead of project_name/public folder.
Reading the html file:
Reading the html files does not depend on the public folder settings. These need not be inside the public folder.
get '/' do
File.read(File.dirname(__FILE__) + '/index.html')
# This says that the app should read the index.html
# Assuming that both myapp.rb and index.html are in the same folder.
# incase the html files are inside a different directory, say, html,
# change that line to:
# File.read(File.dirname(__FILE__) + '/html/index.html')
# Directory structure sample:
# project_name
# | - myapp.rb
# | - index.html (and not html/index.html etc.)
# | /public (or includes incase the css, js assets have a different location)
# | | /css
# | | /js
# | | /images
end
To get the html output inside the browser
After the file is read, typically, this will be your string: "<html><head></head><body></body></html>"
Without escaping the string, the browser renders the html string as html (no pun) and that's why you won't see any text. To escape the html, you can use the CGI class provided by Ruby (hat tip). So, in the end, this will be your snippet:
get '/' do
CGI::escapeHTML(File.read(File.dirname(__FILE__) + 'index.html'))
end
But that will spit out the html file in a single line. To clean it up,
# myapp.rb
get '/' do
#raw_html = CGI::escapeHTML(File.read(File.dirname(__FILE__) + 'index.html'))
end
# Using inline templates to keep things simple.
# get '/' do...end gets the index.erb file and hence, in the inline template,
# we need to use the ## index representation. If we say get '/home' do...end,
# then the inline template will come under ## home. All the html/erb between
# two "##"s will be rendered as one template (also called as view).
# The <%= #raw_html %>spews out the entire html string read inside the "get" block
__END__
## index
<html>
<head></head>
<body>
<pre>
<%= #raw_html %>
</pre>
</body>
</html>
If you're trying to render an index.html file, I would try storing it in the /views directory with an .erb extension. Or use an inline template. Here is a great resource

Maruku tells you: what's wrong with me?

I use jekyll --server to test my site at localhost.
But there are a few lines of input, like this:
___________________________________________________________________________
| Maruku tells you:
+---------------------------------------------------------------------------
| String finished while reading (break on []) already read: "$ git init"
| ---------------------------------------------------------------------------
+---------------------------------------------------------------------------
!/usr/lib/ruby/gems/1.8/gems/maruku-0.6.0/lib/maru/errors_management.rb:49:in `maruku_error'
!/usr/lib/ruby/gems/1.8/gems/maruku-0.6.0/lib/maruku/input/parse_span_better.rb:402:in `read_simple'
!/usr/lib/ruby/gems/1.8/gems/maruku-0.6.0/lib/maruku/input/parse_span_better.rb:521:in `read_inline_code'
!/usr/lib/ruby/gems/1.8/gems/maruku-0.6.0/lib/maruku/input/parse_span_better.rb:89:in `read_span'
!/usr/lib/ruby/gems/1.8/gems/maruku-0.6.0/lib/maruku/input/ parse_span_better.rb:46:in `parse_span_better'
\___________________________________________________________________________
___________________________________________________________________________
| Maruku tells you:
+---------------------------------------------------------------------------
| Could not find ref_id = "url" for md_link(["url"],"url")
| Available refs are []
+---------------------------------------------------------------------------
Not creating a link for ref_id = "url".
I don't know where is wrong, which file I should fix?
The site could still work.
The issue is most likely you have this in your code:
Blah blah [url] blah blah.
If you want to keep square bracket, encode them like this:
Blah blah \[url\] blah blah.
More here: http://daringfireball.net/projects/markdown/syntax#backslash
I came across this, and the cause was the Markdown file had been copied from a GitHub README.md, which contained some GitHub-Flavoured Markdown:
```JavaScript
var foo = 'bar';
```
This works fine inside a GitHub README.md file, but doesn't work with Maruku in Jekyll, which means that it doesn't work when hosting a site with GitHub Pages.

How can I make Jekyll use a layout without specifying it?

In order to keep some of my Jekyll sites simple, I'm always using the same layout. That is to say, I'm always writing something like. . .
---
layout: default
title: Here's my Title
---
. . . as the YAML Front Matter at the top of my pages.
What I'd rather write, however is only. . .
---
title: Here's my Title
---
. . . and have Jekyll assume that it should use a certain layout, as if I had explicitly written "layout: default" (or whatever), as above.
I don't see a way to specify this behavior in _config.yml. Maybe I could write a Jekyll plugin that would allow this. . . any ideas?
This can be done using Frontmatter defaults:
defaults:
-
scope:
path: "" # empty string for all files
values:
layout: "default"
This setting is available since Jekyll Version 2.0.0.
Shorter and with no monkey-patching:
# _plugins/implicit_layout.rb
module ImplicitLayout
def read_yaml(*args)
super
self.data['layout'] ||= 'post'
end
end
Jekyll::Post.send(:include, ImplicitLayout)
Caveat: GH Pages won't run your plugins.
Here's a Jekyll plugin you can drop in as _plugins/implicit-layout.rb, for example:
# By specifying an implicit layout here, you do not need to
# write, for example "layout: default" at the top of each of
# your posts and pages (i.e. in the "YAML Front Matter")
#
# Please note that you should only use this plugin if you
# plan to use the same layout for all your posts and pages.
# To use the plugin, just drop this file in _plugins, calling it
# _plugins/implicit-layout.rb, for example
IMPLICIT_LAYOUT = 'default'
module Jekyll
module Convertible
def read_yaml(base, name)
self.content = File.read(File.join(base, name))
if self.content =~ /^(---\s*\n.*?\n?)^(---\s*$\n?)/m
self.content = $POSTMATCH
begin
self.data = YAML.load($1)
self.data["layout"] = IMPLICIT_LAYOUT
rescue => e
puts "YAML Exception reading #{name}: #{e.message}"
end
end
self.data ||= {}
end
end
end
From hanging out on #jekyll on freenode, I'm given to understand this is a monkey patch.
As Alan W. Smith commented, being able to put "layout: default" in _config.yml would be a nice improvement to this plugin.
Ideally (from my perspective), this functionality could be incorporated in Jekyll itself so a plugin wouldn't be necessary.
By default, you can't do this. Jekyll needs the YAML to specify layout so it knows where to drop it in at.

How can I automatically escape HTML content using Jekyll and Markdown?

In foo.markdown I have the following:
---
layout: default
title: Snarky little Ewok
---
A little Ewok is sometimes referred too as <h3>. But pappa Ewok is called <h1> - if you know what's good for you.
Well, I want Jekyll to automatically html escape the greater than and less than characters. I'm seriously fatigued after today's apprentice training and I'm just too lazy to manually html escape myself: >h3<
Is there a config option or something to automatically escape Jekyll markdown content?
If you used textile instead of markdown, there would be a way.
Liquid markup has textilize & escape filters; those two would allow you to do what you wanted, but on textile. You would have to save your files as text (file extension: txt), and then escape the html before textilizing:
---
layout: default
title: Snarky little Ewok
---
This file's extension is .txt
A little Ewok is sometimes referred too as <h3>. But pappa Ewok is called <h1> - if you know what's good for you.
Then on the default.html layout, instead of having:
{{ page.content }}
You would have this:
{{ page.content | xml_escape | textilize }}
Since there's no 'markdownify' filter on Jekyll yet, you can't do that with markdown. There's an issue (Issue 134) on Jekyll for adding a markdownify filter.
EDIT:
It's now possible to use markdown (since jekyll 0.10.1)
{{ page.content | xml_escape | markdownify }}

Resources