m-chrzan.xyz
aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarcin Chrzanowski <marcin.j.chrzanowski@gmail.com>2019-06-28 19:12:42 +0200
committerMarcin Chrzanowski <marcin.j.chrzanowski@gmail.com>2019-06-28 19:13:20 +0200
commita3b86375c946299c9216412e10c5bcf5234c7fcd (patch)
treeb1cceccafa1fad92561bfda729e2ab9b7b62f1fc
Initial commit
-rw-r--r--.gitignore1
-rw-r--r--.gitlab-ci.yml10
-rw-r--r--lib/blog.rb33
-rw-r--r--lib/pather.rb38
-rw-r--r--lib/statics.rb7
-rw-r--r--lib/templated.rb24
-rwxr-xr-xscripts/build.rb60
-rw-r--r--src/blog.html.erb7
-rw-r--r--src/blog/welcome.html29
-rw-r--r--src/index.html.erb22
-rw-r--r--src/post-template.html.erb2
-rw-r--r--src/projects.html10
-rw-r--r--src/style.css67
-rw-r--r--src/template.html.erb39
14 files changed, 349 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..567609b
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+build/
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
new file mode 100644
index 0000000..417ac35
--- /dev/null
+++ b/.gitlab-ci.yml
@@ -0,0 +1,10 @@
+image: ruby:2.6.3
+
+pages:
+ script:
+ - ruby scripts/build.rb
+ artifacts:
+ paths:
+ - public
+ only:
+ - master
diff --git a/lib/blog.rb b/lib/blog.rb
new file mode 100644
index 0000000..e4403a3
--- /dev/null
+++ b/lib/blog.rb
@@ -0,0 +1,33 @@
+require 'date'
+
+def parse_post filename
+ file_raw = File.read(src filename).force_encoding('UTF-8').split('---')
+ post = YAML.load file_raw[0]
+ post['content'] = file_raw[1].strip
+ post['filename'] = filename
+ post
+end
+
+def generate_blog_post post
+ ERB.new(File.read(src 'post-template.html.erb')).result binding
+end
+
+def posts
+ Dir.new(src 'blog').children.map do |filename|
+ post = parse_post "blog/#{filename}"
+ end.sort do |a, b|
+ Date.parse(b['date']) <=> Date.parse(a['date'])
+ end
+end
+
+def write_blog_files
+ posts.each do |post|
+ content = ERB.new(File.read(src 'post-template.html.erb')).result binding
+ write_templated content, post['filename'], head_title: post['title'], h1_title: 'Blog.'
+ end
+end
+
+def write_blog_archive
+ content = ERB.new(File.read(src 'blog.html.erb')).result
+ write_templated content, 'blog.html', title: 'Blog.'
+end
diff --git a/lib/pather.rb b/lib/pather.rb
new file mode 100644
index 0000000..5ce7d02
--- /dev/null
+++ b/lib/pather.rb
@@ -0,0 +1,38 @@
+class Pather
+ def initialize
+ @assets = {}
+ @current_path = []
+ end
+
+ def add asset_id, path
+ @assets[asset_id] = @current_path + path.split('/')
+ end
+
+ def path_to asset_id
+ other_path = @assets[asset_id]
+ find_path_between @current_path, other_path
+ end
+
+ def find_path_between from, to
+ from, to = drop_common_prefix from, to
+ path = ('../' * from.length) + to.join('/')
+ end
+
+ def drop_common_prefix path1, path2
+ common_prefix_length = path1.zip(path2).take_while do |(segment1, segment2)|
+ segment1 == segment2
+ end.length
+
+ return path1[common_prefix_length..], path2[common_prefix_length..]
+ end
+
+ def cd path
+ path.split('/').each do |segment|
+ if segment == '..'
+ @current_path.pop
+ else
+ @current_path.push segment
+ end
+ end
+ end
+end
diff --git a/lib/statics.rb b/lib/statics.rb
new file mode 100644
index 0000000..3865439
--- /dev/null
+++ b/lib/statics.rb
@@ -0,0 +1,7 @@
+def write_statics statics
+ statics = statics.map do | filename |
+ src filename
+ end
+
+ FileUtils.cp statics, BuildDir
+end
diff --git a/lib/templated.rb b/lib/templated.rb
new file mode 100644
index 0000000..a7e0d63
--- /dev/null
+++ b/lib/templated.rb
@@ -0,0 +1,24 @@
+def template
+ ERB.new(File.read(src 'template.html.erb'))
+end
+
+def write_templated_file content_filename, options
+ content = File.read(src content_filename)
+ write_templated content, content_filename, options
+end
+
+def write_templated_erb erb_filename, options
+ content = ERB.new(File.read(src erb_filename)).result
+ cut_filename = erb_filename.sub /\.erb$/, ''
+ write_templated content, cut_filename, options
+end
+
+# Options should include
+# head_title: used for <title> tag
+# h1_title: used for <h1> on top of page
+# title: used for both of the above, can be overridden with either
+def write_templated content, filename, options
+ head_title = options[:head_title] || options[:title] || ''
+ h1_title = options[:h1_title] || options[:title] || ''
+ File.write build(filename), template.result(binding)
+end
diff --git a/scripts/build.rb b/scripts/build.rb
new file mode 100755
index 0000000..aad1c00
--- /dev/null
+++ b/scripts/build.rb
@@ -0,0 +1,60 @@
+#!/bin/ruby
+require 'erb'
+require 'fileutils'
+require 'yaml'
+
+require './lib/blog'
+require './lib/statics'
+require './lib/pather'
+require './lib/templated'
+
+SourceDir = 'src'
+BuildDir = 'public'
+
+def src filename
+ File.join SourceDir, filename
+end
+
+def build filename
+ File.join BuildDir, filename
+end
+
+def path_to asset_id
+ P.path_to asset_id
+end
+
+if !Dir.exists? 'public'
+ Dir.mkdir 'public'
+end
+
+P = Pather.new
+P.cd 'src'
+
+statics = [
+ 'style.css',
+]
+
+P.add 'style', 'style.css'
+
+P.add 'index', 'index.html'
+P.add 'blog', 'blog.html'
+P.add 'projects', 'projects.html'
+
+if !Dir.exists? 'public/blog'
+ Dir.mkdir 'public/blog'
+end
+
+posts.each do |post|
+ P.add post['title'], post['filename']
+end
+
+write_statics statics
+write_templated_erb 'index.html.erb', title: 'Martin Chrzanowski.'
+write_templated_file 'projects.html', title: 'Projects.'
+write_blog_archive
+
+P.cd 'blog'
+
+write_blog_files
+
+P.cd '..'
diff --git a/src/blog.html.erb b/src/blog.html.erb
new file mode 100644
index 0000000..d89494a
--- /dev/null
+++ b/src/blog.html.erb
@@ -0,0 +1,7 @@
+<ul>
+<% posts.each do |post| %>
+ <li>
+ <a href=<%= path_to post['title'] %>><%= post['title'] %></a> <%= post['date'] %>
+ </li>
+<% end %>
+</ul>
diff --git a/src/blog/welcome.html b/src/blog/welcome.html
new file mode 100644
index 0000000..98de4f5
--- /dev/null
+++ b/src/blog/welcome.html
@@ -0,0 +1,29 @@
+title: Welcome!
+date: June 26, 2019
+---
+<p>
+Hello, internet! In the spirit of
+<a href='http://www.alwaysownyourplatform.com/'>
+<pre>
+(•_•)
+&lt;)  )╯Always
+/  \
+
+\(•_•)
+ (  (&gt; Own
+ /  \
+
+ (•_•)
+&lt;)  )&gt; Your Platform
+ /  \
+</pre>
+</a>
+I've decided to launch my own website and blog.
+</p>
+<p>
+In the spirit of minimalism, it's (as you can see) very bare-bones.
+</p>
+<p>
+In the spirit of self-reliance, it's built with a custom static site generator
+(which is really just a few glorified Ruby scripts) that (again, in the spirit
+of minimalism) do only what I need them to do (and hopefully do so well!).
diff --git a/src/index.html.erb b/src/index.html.erb
new file mode 100644
index 0000000..23f08bc
--- /dev/null
+++ b/src/index.html.erb
@@ -0,0 +1,22 @@
+<p>
+ I am a software engineer, writing smart contracts and other fun things
+ for <a href='https://celo.org'>Celo</a>. I got my bachelor's in computer
+ science at the University of Warsaw.
+</p>
+
+<h2>Recent posts:</h2>
+
+<ul>
+<% posts.take(5).each do |post| %>
+ <li>
+ <a href='<%= path_to post['title'] %>'><%= post['title'] %></a> <%= post['date'] %>
+ </li>
+<% end %>
+</ul>
+
+<hr />
+<ul class='links'>
+ <li><a href='mailto:marcin.j.chrzanowski@gmail.com'>Email</a></li>
+ <li><a href='https://github.com/m-chrzan'>GitHub</a></li>
+ <li><a href='https://linkedin.com/in/marcin-chrzanowski'>LinkedIn</a></li>
+</ul>
diff --git a/src/post-template.html.erb b/src/post-template.html.erb
new file mode 100644
index 0000000..ece1545
--- /dev/null
+++ b/src/post-template.html.erb
@@ -0,0 +1,2 @@
+<h2 style='display: inline'><%= post['title'] %></h2> (<%= post['date'] %>)
+<%= post['content'] %>
diff --git a/src/projects.html b/src/projects.html
new file mode 100644
index 0000000..61363a1
--- /dev/null
+++ b/src/projects.html
@@ -0,0 +1,10 @@
+<ul>
+ <li><a href='https://github.com/m-chrzan/dicebag'>Dicebag</a>: a dice
+ expression parser and roller.
+ </li>
+ <li><a href='#'>This website</a>: a small
+ mess of simple scripts for static site generation. I probably should've
+ used Jekyll, but I wanted to play around and build something minimal for
+ personal use. I'm not a webdev.
+ </li>
+</ul>
diff --git a/src/style.css b/src/style.css
new file mode 100644
index 0000000..70fc10b
--- /dev/null
+++ b/src/style.css
@@ -0,0 +1,67 @@
+body {
+ margin: 40px auto;
+ max-width: 800px;
+ line-height: 1.6;
+ font-size: 18px;
+ padding: 0 10px;
+}
+
+a {
+ color: darkblue;
+ text-decoration: none;
+}
+
+a:hover {
+ color: #55f;
+}
+
+ul {
+ list-style-type: '—';
+}
+
+li {
+ margin-top: 10px;
+ margin-bottom: 10px;
+ text-indent: 0.7em;
+}
+
+h1, h2, h3 {
+ line-height: 1.2
+}
+
+ul.links {
+ list-style-type: none;
+ display: flex;
+ align-items: stretch;
+ justify-content: space-evenly;
+}
+
+.links li {
+ margin-top: 0px;
+ margin-bottom: 0px;
+}
+
+/* note stuff */
+.note {
+ position: relative;
+ vertical-align: baseline;
+}
+
+.note-content {
+ display: none;
+ position: absolute;
+ border: 1px solid black;
+ word-wrap: break-word;
+ background-color: white;
+ font-size: 14px;
+ min-width: 30em;
+ left: 1em;
+ bottom: 0px;
+}
+
+.foot-down a {
+ position: relative;
+ z-index: 1;
+ padding: 10px;
+ margin: -10px;
+}
diff --git a/src/template.html.erb b/src/template.html.erb
new file mode 100644
index 0000000..d61054e
--- /dev/null
+++ b/src/template.html.erb
@@ -0,0 +1,39 @@
+<head>
+ <title><%= head_title %></title>
+ <link rel='stylesheet' type='text/css' href='<%= path_to 'style' %>'>
+ <meta charset='utf8'>
+</head>
+<body>
+ <h1><%= h1_title %></h1>
+
+ <hr />
+
+ <ul class='links'>
+ <li><a href='<%= path_to 'index' %>'>Home</a></li>
+ <li><a id='writings' href='<%= path_to 'blog' %>'>Writings</a></li>
+ <li><a href='<%= path_to 'projects' %>'>Projects</a></li>
+ </ul>
+
+ <hr />
+
+ <%= content %>
+
+ <script type='text/javascript'>
+ var synonyms = [
+ 'Writings',
+ 'Blog',
+ 'Articles',
+ 'Posts',
+ 'Notes',
+ 'Memos',
+ 'Thoughths',
+ 'Words'
+ ]
+ var writings = document.getElementById('writings')
+ writings.addEventListener('mouseenter', function (event) {
+
+ writings.innerHTML =
+ synonyms[Math.floor(Math.random() * synonyms.length)]
+ })
+ </script>
+</body>