implement blog
This commit is contained in:
parent
b4dcd84581
commit
a52f258402
8 changed files with 77 additions and 2 deletions
4
Gemfile
4
Gemfile
|
@ -6,3 +6,7 @@ source "https://rubygems.org"
|
|||
|
||||
gem "phlex", "~> 1.11"
|
||||
gem "phlexite", "~> 0.1.3"
|
||||
|
||||
gem "front_matter_parser", "~> 1.0"
|
||||
|
||||
gem 'phlex-markdown', git: 'https://github.com/phlex-ruby/phlex-markdown'
|
||||
|
|
12
Gemfile.lock
12
Gemfile.lock
|
@ -1,6 +1,16 @@
|
|||
GIT
|
||||
remote: https://github.com/phlex-ruby/phlex-markdown
|
||||
revision: ee1e2763fc842563577003a269982cfc4ac79006
|
||||
specs:
|
||||
phlex-markdown (0.3.0)
|
||||
markly (~> 0.7)
|
||||
phlex (>= 0.5)
|
||||
|
||||
GEM
|
||||
remote: https://rubygems.org/
|
||||
specs:
|
||||
front_matter_parser (1.0.1)
|
||||
markly (0.12.1)
|
||||
phlex (1.11.0)
|
||||
phlexite (0.1.3)
|
||||
|
||||
|
@ -9,7 +19,9 @@ PLATFORMS
|
|||
ruby
|
||||
|
||||
DEPENDENCIES
|
||||
front_matter_parser (~> 1.0)
|
||||
phlex (~> 1.11)
|
||||
phlex-markdown!
|
||||
phlexite (~> 0.1.3)
|
||||
|
||||
BUNDLED WITH
|
||||
|
|
10
build.rb
10
build.rb
|
@ -1,15 +1,25 @@
|
|||
require "phlex"
|
||||
require "phlex/markdown"
|
||||
require "phlexite"
|
||||
require "front_matter_parser"
|
||||
|
||||
require_relative "util/post_loader"
|
||||
require_relative "pages/layout"
|
||||
require_relative "pages/home"
|
||||
require_relative "pages/blog"
|
||||
require_relative "pages/about"
|
||||
require_relative "pages/post"
|
||||
|
||||
Phlexite::Site.new { |s|
|
||||
include Util::PostLoader
|
||||
|
||||
s.mount "assets", on: "/"
|
||||
|
||||
s.page "index.html", Pages::Home.new
|
||||
s.page "blog/index.html", Pages::Blog.new
|
||||
s.page "about/index.html", Pages::About.new
|
||||
|
||||
posts.each do |post|
|
||||
s.page "p/#{post[:slug]}/index.html", Pages::Post.new(post)
|
||||
end
|
||||
}
|
||||
|
|
|
@ -1,7 +1,22 @@
|
|||
class Pages::Blog < ::Phlex::HTML
|
||||
include Util::PostLoader
|
||||
|
||||
def view_template
|
||||
render ::Pages::Layout.new(:blog) {
|
||||
p { "under construction" }
|
||||
ul {
|
||||
posts.each { |post|
|
||||
meta = post[:data].front_matter
|
||||
|
||||
return unless meta.key?('published_on')
|
||||
|
||||
li {
|
||||
p {
|
||||
time(datetime: meta['published_on']) { meta['published_on'] }
|
||||
a(href: '/p/' + post[:slug], style: "padding-left: 10px;") { meta['title'] }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
|
@ -17,12 +17,18 @@ module Pages
|
|||
|
||||
def initialize(page)
|
||||
@page = page
|
||||
if @page.is_a? Symbol
|
||||
@page_info = pages[page]
|
||||
else
|
||||
@page_info = @page
|
||||
end
|
||||
end
|
||||
def view_template
|
||||
|
||||
doctype
|
||||
html {
|
||||
head {
|
||||
title { pages[@page][:title] + " | Aleks Rūtiņš" }
|
||||
title { @page_info[:title] + " | Aleks Rūtiņš" }
|
||||
meta(charset: "utf-8")
|
||||
meta(name: "viewport", content: "width=device-width, initial-scale=1.0")
|
||||
link(rel: "stylesheet", href: "/site.css")
|
||||
|
|
17
pages/post.rb
Normal file
17
pages/post.rb
Normal file
|
@ -0,0 +1,17 @@
|
|||
class Pages::Post < ::Phlex::HTML
|
||||
def initialize(post)
|
||||
@slug = post[:slug]
|
||||
@post = post
|
||||
end
|
||||
def view_template
|
||||
meta = @post[:data].front_matter
|
||||
render ::Pages::Layout.new({title: meta['title']}) {
|
||||
p {
|
||||
h1 { meta['title'] }
|
||||
time(datetime: meta['published_on']) { meta['published_on'] }
|
||||
|
||||
render ::Phlex::Markdown.new(@post[:data].content)
|
||||
}
|
||||
}
|
||||
end
|
||||
end
|
6
posts/2024-10-06-hello-world.md
Normal file
6
posts/2024-10-06-hello-world.md
Normal file
|
@ -0,0 +1,6 @@
|
|||
---
|
||||
title: Hello World
|
||||
published_on: '2024-10-06'
|
||||
---
|
||||
|
||||
Hello, world. This is some **content**.
|
5
util/post_loader.rb
Normal file
5
util/post_loader.rb
Normal file
|
@ -0,0 +1,5 @@
|
|||
module Util
|
||||
module PostLoader
|
||||
def posts = Dir['posts/*.md'].sort.reverse.map { |filename| {slug: File.basename(filename, '.md'), data: FrontMatterParser::Parser.parse_file(filename)} }
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue