Skip to content

Commit

Permalink
Add shortcut icon & opengraph tags
Browse files Browse the repository at this point in the history
  • Loading branch information
hedgehog1029 committed Nov 14, 2019
1 parent 3b714fb commit 40c9ad5
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 0 deletions.
8 changes: 8 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const express = require("express");
const {Watcher} = require("watch-fs");
const {exec} = require("child_process");
const jetpack = require("fs-jetpack");
const {URL} = require("url");
const md = require("markdown-it")();

const posts = require("./lib/posts");
Expand All @@ -21,6 +22,13 @@ app.use("/static", express.static(`${__dirname}/static`));
app.use((req, res, next) => {
res.locals.pageCount = posts.countPages();

let baseUrl = `${req.protocol}://${req.get('Host')}`;
res.locals.asset_url = (path) =>
new URL("/static/" + path, baseUrl).toString();

res.locals.url_for = (post) =>
new URL("/p/" + post.slug, baseUrl).toString();

next(null);
});

Expand Down
Binary file added static/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions views/post.pug
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
extends template.pug

block head
meta(property="og:title" content=post.title)
meta(property="og:type" content="article")
meta(property="og:image" content=asset_url("icon.png"))
meta(property="og:url" content=url_for(post))
meta(property="og:article:published_time" content=(new Date(post.published)).toISOString())
meta(property="og:article:author:username" content=post.author.name)

block content
h1 #{post.title}
div.meta by #{post.author.name} | published #{post.published}
Expand Down
2 changes: 2 additions & 0 deletions views/template.pug
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ html(lang="en")
title the genprog blog
meta(charset="utf-8")
meta(name="viewport" content="width=device-width; initial-scale=1")
link(rel="shortcut icon" type="image/png" href=asset_url("icon.png"))
link(rel="stylesheet" href="/static/pixyll.css")
link(rel="stylesheet" href="/static/tomorrow-night-eighties.min.css")
link(rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/KaTeX/0.6.0/katex.min.css")
block head
body
div.header
h2: a(href="/") the genprog blog
Expand Down

0 comments on commit 40c9ad5

Please sign in to comment.