Added support for a X-Client-Timezone header to convert dates to client's local format gotten from IP using GeoIP.
This commit is contained in:
parent
73795b3755
commit
60ca5a1463
@ -65,6 +65,7 @@ function setRoutes(router) {
|
|||||||
await ctx.render('mindflow', {
|
await ctx.render('mindflow', {
|
||||||
title: "/ Mindflow",
|
title: "/ Mindflow",
|
||||||
description: "Here I will post updates on my infrastructure, my very important opinions and thoughts.",
|
description: "Here I will post updates on my infrastructure, my very important opinions and thoughts.",
|
||||||
|
tz: util.getTimezone(ctx),
|
||||||
diary: await mindflow.getPosts("Diary"),
|
diary: await mindflow.getPosts("Diary"),
|
||||||
updates: await mindflow.getPosts("Update")
|
updates: await mindflow.getPosts("Update")
|
||||||
})
|
})
|
||||||
@ -101,6 +102,7 @@ function setRoutes(router) {
|
|||||||
return await ctx.render('guestbook', {
|
return await ctx.render('guestbook', {
|
||||||
title: "/ Guestbook",
|
title: "/ Guestbook",
|
||||||
description: "This is my guestbook. Welcome.",
|
description: "This is my guestbook. Welcome.",
|
||||||
|
tz: util.getTimezone(ctx),
|
||||||
owner: config.dwelling.guestbook.owner,
|
owner: config.dwelling.guestbook.owner,
|
||||||
posts: posts,
|
posts: posts,
|
||||||
error: posts === null,
|
error: posts === null,
|
||||||
@ -131,8 +133,8 @@ module.exports = () => {
|
|||||||
const pug = new koaPug({
|
const pug = new koaPug({
|
||||||
viewPath: path.join(__dirname, "views", "dwelling"),
|
viewPath: path.join(__dirname, "views", "dwelling"),
|
||||||
locals: {
|
locals: {
|
||||||
date_: date => util.datetime(date, util.formats.post_date),
|
date_: (date, tz) => util.datetime(date, util.formats.post_date, tz),
|
||||||
mindflowDateToId: date => util.datetime(date, util.formats.id_date),
|
mindflowDateToId: (date, tz) => util.datetime(date, util.formats.id_date, tz),
|
||||||
rssLink: util.rssLink },
|
rssLink: util.rssLink },
|
||||||
app: app
|
app: app
|
||||||
});
|
});
|
||||||
@ -140,6 +142,7 @@ module.exports = () => {
|
|||||||
const dwelling_router = koaRouter();
|
const dwelling_router = koaRouter();
|
||||||
setRoutes(dwelling_router);
|
setRoutes(dwelling_router);
|
||||||
|
|
||||||
|
app.proxy = true;
|
||||||
app
|
app
|
||||||
.use(async (ctx, next) => {
|
.use(async (ctx, next) => {
|
||||||
try {
|
try {
|
||||||
|
1
files.js
1
files.js
@ -127,6 +127,7 @@ module.exports = () => {
|
|||||||
const radio_router = koaRouter();
|
const radio_router = koaRouter();
|
||||||
setRoutes(radio_router);
|
setRoutes(radio_router);
|
||||||
|
|
||||||
|
app.proxy = true;
|
||||||
app
|
app
|
||||||
.use(koaRange)
|
.use(koaRange)
|
||||||
.use(radio_router.routes())
|
.use(radio_router.routes())
|
||||||
|
1
radio.js
1
radio.js
@ -52,6 +52,7 @@ module.exports = () => {
|
|||||||
const radio_router = koaRouter();
|
const radio_router = koaRouter();
|
||||||
setRoutes(radio_router);
|
setRoutes(radio_router);
|
||||||
|
|
||||||
|
app.proxy = true;
|
||||||
app
|
app
|
||||||
// .use(koaServe(path.join("static", "shared")))
|
// .use(koaServe(path.join("static", "shared")))
|
||||||
// .use(koaServe(path.join("static", "radio")))
|
// .use(koaServe(path.join("static", "radio")))
|
||||||
|
6
util.js
6
util.js
@ -5,6 +5,11 @@ const formats = Object.freeze({
|
|||||||
file_date: "YYYY-MM-DD HH:mm:ss z",
|
file_date: "YYYY-MM-DD HH:mm:ss z",
|
||||||
id_date: "YYYYMMDD-HHmm" });
|
id_date: "YYYYMMDD-HHmm" });
|
||||||
|
|
||||||
|
function getTimezone(ctx) {
|
||||||
|
if (ctx.header['x-client-timezone'] !== undefined)
|
||||||
|
return ctx.header['x-client-timezone'];
|
||||||
|
}
|
||||||
|
|
||||||
function datetime(date, format=formats.post_date, timezone="UTC") {
|
function datetime(date, format=formats.post_date, timezone="UTC") {
|
||||||
return moment.utc(date).tz(timezone).format(format);
|
return moment.utc(date).tz(timezone).format(format);
|
||||||
}
|
}
|
||||||
@ -20,6 +25,7 @@ exports.getBaseHost = (host) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
exports.getTimezone = getTimezone;
|
||||||
exports.formats = formats;
|
exports.formats = formats;
|
||||||
exports.datetime = datetime;
|
exports.datetime = datetime;
|
||||||
|
|
||||||
|
@ -31,13 +31,13 @@ block content
|
|||||||
each post in posts
|
each post in posts
|
||||||
article
|
article
|
||||||
header
|
header
|
||||||
| Posted by #[span.highlighted= post.name] #{post.email} #{post.website} on #[time(datetime=post.created)= date_(post.created)]
|
| Posted by #[span.highlighted= post.name] #{post.email} #{post.website} on #[time(datetime=post.created)= date_(post.created, tz)]
|
||||||
each line in post.message.split("\n")
|
each line in post.message.split("\n")
|
||||||
p= line
|
p= line
|
||||||
if post.feedback
|
if post.feedback
|
||||||
.feedback
|
.feedback
|
||||||
header
|
header
|
||||||
| Feedback by #[span.highlighted #{owner}] on #[time(datetime=post.feedback_created)= date_(post.feedback_created)]
|
| Feedback by #[span.highlighted #{owner}] on #[time(datetime=post.feedback_created)= date_(post.feedback_created, tz)]
|
||||||
each line in post.feedback.split("\n")
|
each line in post.feedback.split("\n")
|
||||||
p= line
|
p= line
|
||||||
else
|
else
|
||||||
|
@ -18,27 +18,27 @@ block content
|
|||||||
h2 Updates
|
h2 Updates
|
||||||
if (updates)
|
if (updates)
|
||||||
each update in updates
|
each update in updates
|
||||||
article(id='update-'+mindflowDateToId(update.date))
|
article(id='update-'+mindflowDateToId(update.date, tz))
|
||||||
header
|
header
|
||||||
a(href='#update-'+mindflowDateToId(update.date))
|
a(href='#update-'+mindflowDateToId(update.date, tz))
|
||||||
h3= update.title
|
h3= update.title
|
||||||
each line in update.body.split('\n')
|
each line in update.body.split('\n')
|
||||||
p!= line
|
p!= line
|
||||||
footer
|
footer
|
||||||
time(datetime=update.date)= date_(update.date)
|
time(datetime=update.date)= date_(update.date, tz)
|
||||||
else
|
else
|
||||||
p.center No updates? There must be some... Looks like database isn't connected.
|
p.center No updates? There must be some... Looks like database isn't connected.
|
||||||
section
|
section
|
||||||
h2 Diary
|
h2 Diary
|
||||||
if (diary)
|
if (diary)
|
||||||
each entry in diary
|
each entry in diary
|
||||||
article(id='diary-'+mindflowDateToId(entry.date))
|
article(id='diary-'+mindflowDateToId(entry.date, tz))
|
||||||
header
|
header
|
||||||
a(href='#diary-'+mindflowDateToId(entry.date))
|
a(href='#diary-'+mindflowDateToId(entry.date, tz))
|
||||||
h3= entry.title
|
h3= entry.title
|
||||||
each line in entry.body.split('\n')
|
each line in entry.body.split('\n')
|
||||||
p!= line
|
p!= line
|
||||||
footer
|
footer
|
||||||
time(datetime=entry.date)= date_(entry.date)
|
time(datetime=entry.date)= date_(entry.date, tz)
|
||||||
else
|
else
|
||||||
p.center No records? Well, that's definitely something's wrong happened to the database. :(
|
p.center No records? Well, that's definitely something's wrong happened to the database. :(
|
||||||
|
Loading…
Reference in New Issue
Block a user