Skip to content
Permalink
Browse files

Create blog post/overview based on actual metadata

  • Loading branch information...
Jakob Holderbaum
Jakob Holderbaum committed Dec 2, 2018
1 parent d422804 commit 20a511df6b0a91b74b75be5c49364bfaefad8eae
Showing with 30 additions and 17 deletions.
  1. +1 −0 Gemfile
  2. +9 −0 Gemfile.lock
  3. +0 −1 assets/css/style.css
  4. +11 −7 lib/renderer.rb
  5. +5 −5 pages/blog/index.html.erb
  6. +1 −1 partials/footer.html.erb
  7. +1 −1 partials/navigation.html.erb
  8. +2 −2 template-blog.html.erb
@@ -3,5 +3,6 @@ source 'https://rubygems.org'
gem 'faraday'
gem 'kramdown'
gem 'kramdown-metadata-parsers'
gem 'oga'
gem 'sinatra'
gem 'sinatra-contrib'
@@ -6,6 +6,8 @@ GEM
i18n (>= 0.7, < 2)
minitest (~> 5.1)
tzinfo (~> 1.1)
ansi (1.5.0)
ast (2.4.0)
backports (3.11.4)
concurrent-ruby (1.1.3)
faraday (0.15.4)
@@ -19,9 +21,15 @@ GEM
multi_json (1.13.1)
multipart-post (2.0.0)
mustermann (1.0.3)
oga (2.15)
ast
ruby-ll (~> 2.1)
rack (2.0.6)
rack-protection (2.0.4)
rack
ruby-ll (2.1.2)
ansi
ast
sinatra (2.0.4)
mustermann (~> 1.0)
rack (~> 2.0)
@@ -47,6 +55,7 @@ DEPENDENCIES
faraday
kramdown
kramdown-metadata-parsers
oga
sinatra
sinatra-contrib

@@ -863,7 +863,6 @@ section.blog section * {

section.blog section div:first-child {
width: 100%;
height: 200px;
overflow: hidden;
}

@@ -1,5 +1,6 @@
require 'erb'
require 'kramdown'
require 'oga'
require 'yaml'
require 'json'

@@ -84,9 +85,14 @@ def render_page(lang, url, file)
text = File.read(path(file))
doc = Kramdown::Document.new(text, input: 'MetadataKramdown')
result.content = doc.to_html
result.abstract = "This is a blog post"
result.link = "#"
result.meta = doc.root.metadata
result.meta = {}
parsed = Oga.parse_html(result.content)
result.meta[:abstract] = parsed.xpath('p[1]').text
result.meta[:slug] = File.basename(file, '.md')
doc.root.metadata.each do |k, v|
result.meta[k.to_sym] = v
end
result.meta[:date] = result.meta[:date].strftime('%B %-d')
else
result.content = File.read(path(file))
end
@@ -97,7 +103,7 @@ def render_page(lang, url, file)

class Renderer
class RenderedPage
attr_accessor :content, :abstract, :link
attr_accessor :content
attr_writer :meta

def meta
@@ -200,9 +206,7 @@ class TemplateValues < Values
def initialize(lang, url, file, main, meta = {})
super lang, url, file
@main = main
@meta = meta.each_with_object({}) do |(k, v), result|
result[k.to_sym] = v
end
@meta = meta
end

def is_blog_post?
@@ -2,12 +2,12 @@
<section class="blog">
<div>
<h1>Think About! Reading a Blog</h1>
<% blog_posts.each do |post| %><a href="#"><section>
<div><img alt="" src="/assets/images/blog/first-post/thumbnail.png" /></div>
<% blog_posts.each do |post| %><a href="/blog/<%= post.meta[:slug] %>.html"><section>
<div><img alt="" src="/assets/images/blog/<%= post.meta[:slug] %>/header.svg" /></div>
<div>
<span>Chrissi / November 12</span>
<h1><%= post.meta['title'] %></h1>
<p>TDD - especially Unit Testing - has evolved to a known and accepted paradigm in software development. But nevertheless, the test-first approach behind TDD can quickly lead to brittle test code which is hard to understand and to maintain.</p>
<span><%= post.meta[:author] %> / <%= post.meta[:date] %></span>
<h1><%= post.meta[:title] %></h1>
<p><%= post.meta[:abstract] %></p>
<span>Read more</span>
</div>
</section></a><% end %>
@@ -3,7 +3,7 @@
<a id="footer" href="#"><img src="/assets/images/close.svg"/></a>
<a href="/<%= lang %>/"><img src="/assets/images/logo.svg" alt="Think About! Logo"/></a>
<ul>
<li><a href="/<%= lang %>/blog/">Blog</a></li>
<li><a href="/blog/">Blog</a></li>
<li><a href="/<%= lang %>/consensus.html"><%= t('nav.consensus') %></a></li>
<li><a href="/<%= lang %>/about-us.html"><%= t('nav.about-us') %></a></li>
<li><a href="/<%= lang %>/about.html"><%= t('nav.imprint') %></a></li>
@@ -5,7 +5,7 @@
<div>
<a href="/<%= lang %>/"><img src="/assets/images/logo.svg" alt="Think About! Logo"/></a>
<ul>
<li><a href="/<%= lang %>/blog/">Blog</a></li>
<li><a href="/blog/">Blog</a></li>
<li><a href="/<%= lang %>/consensus.html"><%= t('nav.consensus') %></a></li>
<li><a href="/<%= lang %>/about-us.html"><%= t('nav.about-us') %></a></li>
<li><a button href="tickets.html"><%= t('nav.tickets') %></a></li>
@@ -10,8 +10,8 @@
<section class="blogpost">
<div>
<h1><%= meta[:title] %></h1>
<span>Published at December 2nd by Jakob</span>
<img src="/assets/images/blog/launching-a-conference/header.png" />
<span>Published at <%= meta[:date] %> by <%= meta[:author] %></span>
<img src="/assets/images/blog/<%= meta[:slug] %>/header.svg" />
<%= main %>
<div class="centered">
<p>Share this article:</p>

0 comments on commit 20a511d

Please sign in to comment.
You can’t perform that action at this time.