commit 921f55b5e1e16c4960ad57f62cef38838d1d5dc2
parent 7c3b0c7b88d7c6966890f48ad92a3d2a45534eca
Author: Remy Noulin <loader2x@gmail.com>
Date: Thu, 11 Jun 2020 13:02:00 +0200
fix bug: process "{% post_url..." outside code block only
- add markdown examples
- fix link to forb git
README.md | 35 ++++++++++++++++-
forb.c | 45 ++++++++++++++--------
package.yml | 2 +-
.../_posts/2020-06-09-getting-started.markdown | 33 ++++++++++++++++
template/about.md | 35 ++++++++++++++++-
5 files changed, 131 insertions(+), 19 deletions(-)
Diffstat:
5 files changed, 131 insertions(+), 19 deletions(-)
diff --git a/README.md b/README.md
@@ -5,7 +5,7 @@ Forb is a blogging system using configurations similar to [jekyll](https://jekyl
- Run `forb new` to copy the default template to the current directory
- Run `forb` to generate the site in the `_site` directory
-The source code is available at [forb git](https://noulin.net/forb)
+The source code is available at [forb git](https://noulin.net/forb/file/README.md.html)
# Install
@@ -26,3 +26,36 @@ Add your posts in the `_posts` directory, with filenames in the format:
For example:
`2020-06-09-getting-started.markdown`
+
+# About markdown
+
+The markdown standard in forb is `CommonMark` with tables.
+
+- Table example:
+```
+| Line 1, Column A - Title line in Bold | Column B - Title line in Bold |
+| Line 2, A | 2B |
+
+```
+
+- Link to external page:
+```
+(title)[url]
+```
+
+- Image in post:
+```
+!(title)[%baseurl/images/img.png]
+
+When baseurl="/blog", write:
+!(title)[/blog/images/img.png]
+```
+
+- Link to another post in blog:
+```
+[another post](_%baseurl{% post_url POST_FILENAME_WITHOUT_MARKDOWN_EXTENSION %})
+
+Keep "_%baseurl", forb replaces it with the value in _config.yml,
+after post_url write the post filename to be linked without ".markdown":
+[another post](_%baseurl{% post_url 2020-06-09-getting-started %})
+```
diff --git a/forb.c b/forb.c
@@ -277,6 +277,11 @@ bool readFileWithFrontMatter(char *filename, smallJsont *kv, smallArrayt *lines)
// parse yml code in front matter
// remove front matter from lines
+ if (not isPath(filename)) {
+ logE("File '%s' not found.", filename);
+ ret no;
+ }
+
readFileG(lines, filename);
// find front matter start and end
@@ -293,6 +298,11 @@ bool readFileWithFrontMatter(char *filename, smallJsont *kv, smallArrayt *lines)
}
}
+ if (frontMatterStart == -1 or frontMatterEnd == -1) {
+ logE("front matter not found in '%s'", filename);
+ ret no;
+ }
+
// parse yml code in front matter
var frontMatter = copyRngG(lines, frontMatterStart, frontMatterEnd);
@@ -310,7 +320,7 @@ bool readFileWithFrontMatter(char *filename, smallJsont *kv, smallArrayt *lines)
sliceG(lines, frontMatterEnd+1, 0);
//lv(lines);
- ret true;
+ ret yes;
}
/**
@@ -397,21 +407,6 @@ bool generateAPageOrAPost(char *filename, smallJsont *cfg, smallArrayt *postsFee
int lastCodeHighlightingLine = -1;
iter(pHtml, L) {
castS(l,L);
- // process {% post_url 2015-12-22-running-rocket-chat %}
- if (hasG(l, "{\% post_url ")) {
- char *startp = hasG(l, "{\% post_url ");
- char *endp = hasG(l, " \%}");
- int start = startp - ssGet(l);
- int end = endp - ssGet(l);
- // post filename
- char *postFilemane = startp + strlen("{\% post_url ");
- *endp = 0;
- //lv(postFilemane);
- cleanCharP(url) = postToUrl(postFilemane);
- delG(l, start, end+3);
- insertG(l, start, url);
- //lv(l);
- }
// code highlighting
if (status == searchCode and hasG(l, "<code>")) {
if (hasG(l, "<pre><code>")) {
@@ -626,6 +621,24 @@ bool generateAPageOrAPost(char *filename, smallJsont *cfg, smallArrayt *postsFee
}
}
+ // process {% post_url 2015-12-22-running-rocket-chat %}
+ // only outside code block, keep inside code blocks
+ // (keep this block after code highlighting to get the correct status from the first line
+ // in the code block)
+ if (status == searchCode and hasG(l, "{\% post_url ")) {
+ char *startp = hasG(l, "{\% post_url ");
+ char *endp = hasG(l, " \%}");
+ int start = startp - ssGet(l);
+ int end = endp - ssGet(l);
+ // post filename
+ char *postFilemane = startp + strlen("{\% post_url ");
+ *endp = 0;
+ //lv(postFilemane);
+ cleanCharP(url) = postToUrl(postFilemane);
+ delG(l, start, end+3);
+ insertG(l, start, url);
+ //lv(l);
+ }
setPG(pHtml, iterIndexG(pHtml), l);
}
diff --git a/package.yml b/package.yml
@@ -1,6 +1,6 @@
---
name: forb
- version: 0.0.4
+ version: 0.0.5
description: static blog generator with configuration files inspired by jekyll
bin: ./forb.c
repository:
diff --git a/template/_posts/2020-06-09-getting-started.markdown b/template/_posts/2020-06-09-getting-started.markdown
@@ -9,3 +9,36 @@ Forb is blogging system using configurations similar to [jekyll](https://jekyllr
- Run `forb new` to copy the default template to the current directory
- Run `forb` to generate the site (saved under the `_site` directory)
+
+# About markdown
+
+The markdown standard in forb is `CommonMark` with tables.
+
+- Table example:
+```
+| Line 1, Column A - Title line in Bold | Column B - Title line in Bold |
+| Line 2, A | 2B |
+
+```
+
+- Link to external page:
+```
+(title)[url]
+```
+
+- Image in post:
+```
+!(title)[%baseurl/images/img.png]
+
+When baseurl="/blog", write:
+!(title)[/blog/images/img.png]
+```
+
+- Link to another post in blog:
+```
+[another post](_%baseurl{% post_url POST_FILENAME_WITHOUT_MARKDOWN_EXTENSION %})
+
+Keep "_%baseurl", forb replaces it with the value in _config.yml,
+after post_url write the post filename to be linked without ".markdown":
+[another post](_%baseurl{% post_url 2020-06-09-getting-started %})
+```
diff --git a/template/about.md b/template/about.md
@@ -7,4 +7,37 @@ permalink: /about/
This is forb's default template.
You can find the source code for forb at:
-[forb git](https://noulin.net/forb)
+[forb git](https://noulin.net/forb/file/README.md.html)
+
+# About markdown
+
+The markdown standard in forb is `CommonMark` with tables.
+
+- Table example:
+```
+| Line 1, Column A - Title line in Bold | Column B - Title line in Bold |
+| Line 2, A | 2B |
+
+```
+
+- Link to external page:
+```
+(title)[url]
+```
+
+- Image in post:
+```
+!(title)[%baseurl/images/img.png]
+
+When baseurl="/blog", write:
+!(title)[/blog/images/img.png]
+```
+
+- Link to another post in blog:
+```
+[another post](_%baseurl{% post_url POST_FILENAME_WITHOUT_MARKDOWN_EXTENSION %})
+
+Keep "_%baseurl", forb replaces it with the value in _config.yml,
+after post_url write the post filename to be linked without ".markdown":
+[another post](_%baseurl{% post_url 2020-06-09-getting-started %})
+```