aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--data/themes/default/templates/blog-post.html21
-rw-r--r--src/guff/handlers.cr11
-rw-r--r--src/guff/views/blog/post.cr23
-rw-r--r--src/views/blog/post.ecr4
4 files changed, 48 insertions, 11 deletions
diff --git a/data/themes/default/templates/blog-post.html b/data/themes/default/templates/blog-post.html
new file mode 100644
index 0000000..f1eaeb4
--- /dev/null
+++ b/data/themes/default/templates/blog-post.html
@@ -0,0 +1,21 @@
+<!DOCTYPE html>
+<html lang='en-US'>
+ <head>
+ <meta charset="utf-8"/>
+ <title>%{name|h}</title>
+
+ %{styles}
+ </head>
+
+ <body class='guff-blog-post'>
+ <b>blog post: %{name|h}</b><br/>
+ <b>
+ by <span class='user'>%{user_name|h}</span>
+ on <span class='date'>%{posted_at_text|h}</span>
+ </b><br/><br/>
+
+ %{body}
+ </body>
+
+ %{scripts}
+</html>
diff --git a/src/guff/handlers.cr b/src/guff/handlers.cr
index f0a8571..2670f89 100644
--- a/src/guff/handlers.cr
+++ b/src/guff/handlers.cr
@@ -444,20 +444,21 @@ module Guff::Handlers
$}x
def call(context : HTTP::Server::Context)
- if r = get(context.request)
+ site_id, r = get(context.request)
+ if site_id && r
context.response.headers["x-frame-options"] = "SAMEORIGIN"
context.response.content_type = "text/html; charset=utf-8"
context.response.status_code = 200
- Views::Blog::PostView.new(@context, r).to_s(context.response)
+ Views::Blog::PostView.new(@context, site_id, r).to_s(context.response)
else
# unknown page
call_next(context)
end
end
- private def get(request : HTTP::Request) : Hash(String, String)?
- r = nil
+ private def get(request : HTTP::Request)
+ site_id, r = nil, nil
if request.method == "GET"
if md = PATH_RE.match(request.path.not_nil!)
@@ -478,7 +479,7 @@ module Guff::Handlers
end
# return result
- r
+ {site_id, r}
end
end
diff --git a/src/guff/views/blog/post.cr b/src/guff/views/blog/post.cr
index 4b1dc1e..4bc5282 100644
--- a/src/guff/views/blog/post.cr
+++ b/src/guff/views/blog/post.cr
@@ -1,7 +1,20 @@
-class Guff::Views::Blog::PostView < Guff::Views::HTMLView
- def initialize(context : Context, @item : Hash(String, String))
- super(context)
- end
+require "../template-html"
+
+class Guff::Views::Blog::PostView < Guff::Views::TemplateHTMLView
+ def initialize(
+ context : Context,
+ site_id : Int64,
+ item : Hash(String, String)
+ )
+ # get site details
+ site = context.models.site.get(site_id)
- ECR.def_to_s("src/views/blog/post.ecr")
+ super(
+ context: context,
+ theme_id: site["theme_id"].as(Int64).to_i32,
+ theme_slug: site["theme_slug"].as(String),
+ template_id: "blog-post.html",
+ data: item,
+ )
+ end
end
diff --git a/src/views/blog/post.ecr b/src/views/blog/post.ecr
index d0aa534..08ac564 100644
--- a/src/views/blog/post.ecr
+++ b/src/views/blog/post.ecr
@@ -1,4 +1,6 @@
-<!DOCTYPE html>
+<%
+ # deprecated: switched to theme templates
+%><!DOCTYPE html>
<html lang='en-US'>
<head>
<meta charset="utf-8"/>