aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTanguy Andreani <tanguy.andreani@tuta.io>2021-11-20 23:10:07 +0100
committerTanguy Andreani <tanguy.andreani@tuta.io>2021-11-20 23:10:07 +0100
commit0d7a7d81ba6300a25cf4f0a41de08dccb98d02a3 (patch)
tree1ad6a595ac90f2075e07f26cbbb9907d2bc5ced9
parentfecc37cc0c81723f39fcdcecd92dfea5ca919469 (diff)
downloadpandoc-blog-master.tar.gz
replace bash with a ruby scriptHEADmaster
-rw-r--r--2021-11-20-My-awesome-first-post.markdown23
-rw-r--r--README.md4
-rwxr-xr-xbuild.rb132
-rwxr-xr-xbuild.sh22
-rw-r--r--footer.html4
-rw-r--r--header-index.html1
-rw-r--r--header.html13
-rw-r--r--index.css23
-rwxr-xr-xindex.sh9
-rw-r--r--mathjax.html4
-rwxr-xr-xnewpost.sh28
-rw-r--r--pandoc.css97
12 files changed, 306 insertions, 54 deletions
diff --git a/2021-11-20-My-awesome-first-post.markdown b/2021-11-20-My-awesome-first-post.markdown
new file mode 100644
index 0000000..8e8365a
--- /dev/null
+++ b/2021-11-20-My-awesome-first-post.markdown
@@ -0,0 +1,23 @@
+---
+title: My title!
+mathjax: true
+draft: false
+date: 2021-11-20
+permalink: 2021-11-20-My-awesome-first-post.html
+---
+
+<div class="abstract">
+First lines
+</div>
+
+When $a \ne 0$, there are two solutions to $ax^2 + bx + c = 0$ and they are
+ $$x = {-b \pm \sqrt{b^2-4ac} \over 2a}$$
+
+And here is some quote:
+
+>Lorem ipsum dolor sit amet!
+
+
+```js
+console.log('hello')
+```
diff --git a/README.md b/README.md
index 300301b..13bb00a 100644
--- a/README.md
+++ b/README.md
@@ -2,9 +2,9 @@
```bash
# Create new post
-./newpost my-first-post
+./newpost.sh "My first post!"
edit ./2021-05-14-my-first-post.markdown
# Generate whole site
-./index.sh
+./build.rb
```
diff --git a/build.rb b/build.rb
new file mode 100755
index 0000000..d0273ab
--- /dev/null
+++ b/build.rb
@@ -0,0 +1,132 @@
+#!/usr/bin/env ruby
+
+=begin
+(The code in this file which handles YAML front matters belongs to the Jekyll
+static site generator.)
+
+The MIT License (MIT)
+
+Copyright (c) 2008-present Tom Preston-Werner and Jekyll contributors
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
+=end
+
+$blog_title = 'my blog'
+$default_post_title = 'please give me a title'
+
+require 'psych'
+require 'date'
+
+YAML_FRONT_MATTER_REGEXP = %r!\A(---\s*\n.*?\n?)^((---|\.\.\.)\s*$\n?)!m.freeze
+
+filenames = Dir["*.markdown"]
+
+index = []
+
+def get_front_matter filename
+ content = ''
+ data = {}
+
+ begin
+ content = File.read(filename)
+ if content =~ YAML_FRONT_MATTER_REGEXP
+ #content = Regexp.last_match.post_match
+ data = Psych.safe_load(Regexp.last_match(1), permitted_classes: [Date])
+ end
+ rescue Psych::SyntaxError => e
+ $stderr.puts "YAML Exception reading #{filename}: #{e.message}"
+ raise e
+ rescue StandardError => e
+ $stderr.puts "Error reading file #{filename}: #{e.message}"
+ raise e
+ end
+
+ [data, ''] # empty string used to be `content`
+end
+
+def pandoc_command_for filename, front_matter, content
+ data = front_matter
+
+ data['permalink'] ||= filename.gsub(/\.markdown$/, '.html')
+ data['title'] ||= $default_post_title
+
+ options = []
+ options << 'pandoc'
+ options << '-s'
+
+ if data['mathjax']
+ options << '--mathjax'
+ options << '-H mathjax.html'
+ end
+
+ options << '-c typesafe.css -c pandoc.css -A footer.html'
+
+ options << '-B header.html'
+
+ if filename != './index.markdown'
+ #options << '--toc'
+ else
+ options << '-c index.css'
+ end
+
+ options << "--metadata pagetitle=\"#{data['title']} - #{$blog_title}\""
+
+ options << "\"#{filename}\" -o \"#{data['permalink']}\""
+
+ options.join(' ')
+end
+
+filenames.each { |filename|
+ next if filename == 'index.markdown'
+
+ data, content = get_front_matter filename
+
+ if data['draft']
+ next
+ end
+
+ index << {
+ filename: filename,
+ date: data['date'],
+ title: data['title'],
+ permalink: data['permalink']
+ }
+
+ command = pandoc_command_for filename, data, content
+ print `#{command} 2>&1`
+}
+
+index.sort_by! { |page|
+ page[:date]
+}.reverse!
+
+File.open("./index.markdown","w") do |line|
+ line.puts """---
+title: #{$blog_title}
+permalink: index.html
+---
+ """
+
+ index.each { |page|
+ line.puts "- #{page[:date].to_s.gsub(/-/, '/')}: [#{page[:title]}](#{page[:permalink]})\n"
+ }
+end
+
+data, content = get_front_matter './index.markdown'
+print `#{pandoc_command_for './index.markdown', data, content} 2>&1` \ No newline at end of file
diff --git a/build.sh b/build.sh
deleted file mode 100755
index e2d50ca..0000000
--- a/build.sh
+++ /dev/null
@@ -1,22 +0,0 @@
-#!/bin/bash
-set -e
-for f in $(find . -name '*.markdown' -type f); do
- if [ ${f} != "./index.markdown" ]; then
- toc="--toc"
- header="-H header.html"
- headline=$(head -1 $f | sed 's/^# //')
- else
- header="-H header-index.html"
- headline="Index"
- fi
- echo "Processing ${f}"
- pandoc \
- -s \
- ${toc} \
- -c typesafe.css \
- -c pandoc.css \
- -A footer.html \
- ${header} \
- --metadata pagetitle="$headline - lmbdfn's music blog" \
- "${f}" -o "${f/.markdown/.html}"
-done
diff --git a/footer.html b/footer.html
index a864604..0d5948d 100644
--- a/footer.html
+++ b/footer.html
@@ -1 +1,3 @@
-<p><i>This is a website where I write about stuff I do.</i></p>
+<footer>
+ <p><i>This is a website where I write about stuff I do.</i></p>
+</footer>
diff --git a/header-index.html b/header-index.html
deleted file mode 100644
index 1eb201e..0000000
--- a/header-index.html
+++ /dev/null
@@ -1 +0,0 @@
-<h1>My simple blog</h1>
diff --git a/header.html b/header.html
index a0eff96..e14c94d 100644
--- a/header.html
+++ b/header.html
@@ -1,3 +1,12 @@
-<p><a href="./index.html">Index</a> | <a href="#">Other link</a></p>
+<nav>
+ <!--<p>Tanguy Andreani</p>
+ <hr>-->
+ <div class="top-links">
+ (menu '<a href="./index.html">Index</a>
+ '<a href="#">Other link</a>
+ '<a href="#">Facebook</a>)
+ </div>
+</nav>
-<h3>Table of contents</h3>
+
+<!--<h3>Table of contents</h3>-->
diff --git a/index.css b/index.css
new file mode 100644
index 0000000..2579065
--- /dev/null
+++ b/index.css
@@ -0,0 +1,23 @@
+ul {
+ list-style-type: none;
+
+ margin: 0;
+ padding: 0;
+}
+
+ul li {
+ line-height: 1.1rem;
+
+ margin: 0;
+ padding: 0;
+}
+
+li {
+ font-family: 'Courier Prime', 'Courier New', Courier, monospace;
+}
+
+li a, li a:visited, li a:hover {
+ font-family: 'Courier Prime', 'Courier New', Courier, monospace;
+ font-weight: 700;
+ color: #333;
+} \ No newline at end of file
diff --git a/index.sh b/index.sh
deleted file mode 100755
index 07e5d84..0000000
--- a/index.sh
+++ /dev/null
@@ -1,9 +0,0 @@
-#!/bin/bash
-set -e
-rm -f index.markdown
-sorted=$(ls *.markdown)
-for f in ${sorted}; do
- headline=$(head -1 $f | sed 's/^# //')
- echo "- [${f:0:10} ${headline}](${f/.markdown/.html})" >> index.markdown
-done
-bash ./build.sh
diff --git a/mathjax.html b/mathjax.html
new file mode 100644
index 0000000..802621a
--- /dev/null
+++ b/mathjax.html
@@ -0,0 +1,4 @@
+<script src="https://polyfill.io/v3/polyfill.min.js?features=es6"></script>
+<script id="MathJax-script" async
+ src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js">
+</script> \ No newline at end of file
diff --git a/newpost.sh b/newpost.sh
index 66cc846..00b6dc5 100755
--- a/newpost.sh
+++ b/newpost.sh
@@ -1,12 +1,30 @@
#!/bin/bash
set -e
today=$(date +'%Y-%m-%d')
-cat > ${today}-${1}.markdown <<EOFF
-# What I practiced this week
+title="${1}"
+title_min=$(ruby -e "print '${1}'.strip.gsub(/\s/, '-').gsub(/[^a-zA-Z0-9\-]/, '')")
+cat > "${today}-${title_min}.markdown" <<EOFF
+---
+title: My title!
+mathjax: false
+draft: true
+date: ${today}
+permalink: ${today}-${title_min}.html
+---
<div class="dates">
-Date of first word: $today
-
-Date of publishing: FILLME
+First lines
</div>
+
+When \$a \\ne 0$, there are two solutions to \$ax^2 + bx + c = 0\$ and they are
+ \$\$x = {-b \\pm \\sqrt{b^2-4ac} \\over 2a}\$\$
+
+And here is [some](https://google.fr) quote:
+
+>Lorem ipsum dolor sit amet!
+
+
+\`\`\`js
+console.log('hello')
+\`\`\`
EOFF
diff --git a/pandoc.css b/pandoc.css
index 7566f6c..57e80ef 100644
--- a/pandoc.css
+++ b/pandoc.css
@@ -1,37 +1,110 @@
+@import url('https://fonts.googleapis.com/css2?family=Courier+Prime:wght@400;700&display=swap');
+
+*, *::after, *::before {
+ box-sizing: border-box;
+}
+
body
{
- background: #fefefe;
- color: #444;
+ background: #F3F4ED;
+ color: #333;
}
a, a:visited, a:hover
{
- color: rgb(255, 0, 119);
+ color: #1a7c86;
}
html
{
- border-top: 4px solid #666;
+ border-top: 4px solid #444;
}
body
{
- margin: 0;
+ max-width: 880px;
+ margin: 0 auto;
}
-body > *:first-child
-{
- margin-top: 0;
+.abstract::before {
+ display: inline;
+ content: "ABSTRACT";
+ font-weight: 700;
}
-.dates
+.abstract
{
- display: inline-block;
- background: #eee;
+ display: block;
+ border: 1px solid #bbb;
+ background: #fff;
padding: 1rem;
}
-.dates > *
+.abstract > *
{
margin: 0;
+ display: inline;
+}
+
+/* hide pandoc date */
+p.date {
+ display: none;
}
+
+#title-block-header > h1 {
+ text-transform: uppercase;
+ text-align: left;
+ font-size: 1.2rem;
+ border-bottom: 1px solid #bbb;
+ padding: 0;
+ margin: 0;
+ margin-bottom: 0.5rem;
+ font-family: 'Courier Prime', 'Courier New', Courier, monospace;
+}
+
+pre {
+ background-color: #f8f8f6;
+ border: 1px dotted #444;
+}
+
+blockquote {
+ background-color: #eceee8;
+ border-top: 1px solid #ddd;
+ border-right: 1px solid #ddd;
+ border-bottom: 1px solid #ddd;
+}
+
+.top-links {
+ font-family: 'Courier Prime', 'Courier New', Courier, monospace;
+ color: #aaa;
+ font-weight: bolder;
+}
+
+.top-links a, .top-links a:visited, .top-links a:hover {
+ text-decoration: none;
+ color: #333;
+ font-family: 'Courier Prime', 'Courier New', Courier, monospace;
+}
+
+.top-links a:not(:last-child) {
+ margin-right: 0px;
+}
+
+nav {
+ max-width: fit-content;
+ margin: 0 auto;
+ font-size: 1.2rem;
+ margin-bottom: 3rem;
+ margin-top: 0.5rem;
+ text-transform: uppercase;
+}
+
+footer {
+ margin-top: 1rem;
+ padding-top: 0;
+ border-top: 1px dotted #999;
+}
+
+footer > *:first-child {
+ margin-top: 0.5rem;
+} \ No newline at end of file