mirror of
https://git.sr.ht/~cadence/bibliogram
synced 2024-11-22 16:17:29 +00:00
Implement SPA setting (closes #35)
This commit is contained in:
parent
850ea94ae8
commit
d83a5de095
@ -88,7 +88,7 @@ let constants = {
|
|||||||
name: "spa",
|
name: "spa",
|
||||||
default: "on",
|
default: "on",
|
||||||
boolean: true,
|
boolean: true,
|
||||||
replaceEmptyWithDefault: true
|
replaceEmptyWithDefault: false
|
||||||
},{
|
},{
|
||||||
name: "theme",
|
name: "theme",
|
||||||
default: "classic",
|
default: "classic",
|
||||||
|
@ -3,6 +3,7 @@ const switcher = require("../../lib/utils/torswitcher")
|
|||||||
const {fetchUser, getOrFetchShortcode, userRequestCache, history} = require("../../lib/collectors")
|
const {fetchUser, getOrFetchShortcode, userRequestCache, history} = require("../../lib/collectors")
|
||||||
const {render, redirect, getStaticURL} = require("pinski/plugins")
|
const {render, redirect, getStaticURL} = require("pinski/plugins")
|
||||||
const {pugCache} = require("../passthrough")
|
const {pugCache} = require("../passthrough")
|
||||||
|
const {getSettings} = require("./utils/getsettings")
|
||||||
|
|
||||||
/** @param {import("../../lib/structures/TimelineEntry")} post */
|
/** @param {import("../../lib/structures/TimelineEntry")} post */
|
||||||
function getPageTitle(post) {
|
function getPageTitle(post) {
|
||||||
@ -57,7 +58,7 @@ module.exports = [
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
route: `/u/(${constants.external.username_regex})`, methods: ["GET"], code: ({url, fill}) => {
|
route: `/u/(${constants.external.username_regex})`, methods: ["GET"], code: ({req, url, fill}) => {
|
||||||
if (fill[0] !== fill[0].toLowerCase()) { // some capital letters
|
if (fill[0] !== fill[0].toLowerCase()) { // some capital letters
|
||||||
return Promise.resolve(redirect(`/u/${fill[0].toLowerCase()}`, 301))
|
return Promise.resolve(redirect(`/u/${fill[0].toLowerCase()}`, 301))
|
||||||
}
|
}
|
||||||
@ -69,7 +70,10 @@ module.exports = [
|
|||||||
await user.timeline.fetchUpToPage(page - 1)
|
await user.timeline.fetchUpToPage(page - 1)
|
||||||
}
|
}
|
||||||
const followerCountsAvailable = !(user.constructor.name === "ReelUser" && user.following === 0 && user.followedBy === 0)
|
const followerCountsAvailable = !(user.constructor.name === "ReelUser" && user.following === 0 && user.followedBy === 0)
|
||||||
return render(200, "pug/user.pug", {url, user, followerCountsAvailable, constants})
|
|
||||||
|
const settings = getSettings(req)
|
||||||
|
|
||||||
|
return render(200, "pug/user.pug", {url, user, followerCountsAvailable, constants, settings})
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
if (error === constants.symbols.NOT_FOUND || error === constants.symbols.ENDPOINT_OVERRIDDEN) {
|
if (error === constants.symbols.NOT_FOUND || error === constants.symbols.ENDPOINT_OVERRIDDEN) {
|
||||||
return render(404, "pug/friendlyerror.pug", {
|
return render(404, "pug/friendlyerror.pug", {
|
||||||
@ -173,15 +177,19 @@ module.exports = [
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
route: `/p/(${constants.external.shortcode_regex})`, methods: ["GET"], code: ({fill}) => {
|
route: `/p/(${constants.external.shortcode_regex})`, methods: ["GET"], code: ({req, fill}) => {
|
||||||
return getOrFetchShortcode(fill[0]).then(async post => {
|
return getOrFetchShortcode(fill[0]).then(async post => {
|
||||||
await post.fetchChildren()
|
await post.fetchChildren()
|
||||||
await post.fetchExtendedOwnerP() // serial await is okay since intermediate fetch result is cached
|
await post.fetchExtendedOwnerP() // serial await is okay since intermediate fetch result is cached
|
||||||
if (post.isVideo()) await post.fetchVideoURL()
|
if (post.isVideo()) await post.fetchVideoURL()
|
||||||
|
|
||||||
|
const settings = getSettings(req)
|
||||||
|
|
||||||
return render(200, "pug/post.pug", {
|
return render(200, "pug/post.pug", {
|
||||||
title: getPageTitle(post),
|
title: getPageTitle(post),
|
||||||
post,
|
post,
|
||||||
website_origin: constants.website_origin
|
website_origin: constants.website_origin,
|
||||||
|
settings
|
||||||
})
|
})
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
if (error === constants.symbols.NOT_FOUND) {
|
if (error === constants.symbols.NOT_FOUND) {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
//- Needs website_origin, title, post
|
//- Needs website_origin, title, post, settings
|
||||||
|
|
||||||
include includes/post
|
include includes/post
|
||||||
|
|
||||||
@ -7,7 +7,8 @@ html
|
|||||||
head
|
head
|
||||||
title= title
|
title= title
|
||||||
include includes/head
|
include includes/head
|
||||||
script(type="module" src=getStaticURL("html", "/static/js/post_overlay.js"))
|
if settings.spa
|
||||||
|
script(type="module" src=getStaticURL("html", "/static/js/post_overlay.js"))
|
||||||
meta(property="og:url" content=`${website_origin}/p/${post.data.shortcode}`)
|
meta(property="og:url" content=`${website_origin}/p/${post.data.shortcode}`)
|
||||||
meta(property="og:type" content="article")
|
meta(property="og:type" content="article")
|
||||||
- let firstEntry = post.children[0]
|
- let firstEntry = post.children[0]
|
||||||
|
@ -49,7 +49,7 @@ html
|
|||||||
|
|
||||||
+checkbox("link_hashtags", "Clickable hashtags", "Clickable", true)
|
+checkbox("link_hashtags", "Clickable hashtags", "Clickable", true)
|
||||||
|
|
||||||
+checkbox("spa", "Fast navigation", "Enabled", true)
|
+checkbox("spa", "Fast navigation", "Enabled", false)
|
||||||
|
|
||||||
+fieldset("Appearance")
|
+fieldset("Appearance")
|
||||||
+select("theme", "Theme", true, [
|
+select("theme", "Theme", true, [
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
//- Needs user, followerCountsAvailable, url, constants
|
//- Needs user, followerCountsAvailable, url, constants, settings
|
||||||
|
|
||||||
include includes/timeline_page.pug
|
include includes/timeline_page.pug
|
||||||
include includes/next_page_button.pug
|
include includes/next_page_button.pug
|
||||||
@ -15,7 +15,10 @@ html
|
|||||||
else
|
else
|
||||||
title= `@${user.data.username} | Bibliogram`
|
title= `@${user.data.username} | Bibliogram`
|
||||||
include includes/head
|
include includes/head
|
||||||
script(src=getStaticURL("html", "/static/js/post_overlay.js") type="module")
|
if settings.spa
|
||||||
|
script(src=getStaticURL("html", "/static/js/post_overlay.js") type="module")
|
||||||
|
else
|
||||||
|
script(src=getStaticURL("html", "/static/js/pagination.js") type="module")
|
||||||
meta(property="og:url" content=`${constants.website_origin}/u/${user.data.username}`)
|
meta(property="og:url" content=`${constants.website_origin}/u/${user.data.username}`)
|
||||||
meta(property="og:type" content="profile")
|
meta(property="og:type" content="profile")
|
||||||
meta(property="og:title" content=(user.data.full_name || user.data.username))
|
meta(property="og:title" content=(user.data.full_name || user.data.username))
|
||||||
|
Loading…
Reference in New Issue
Block a user