mirror of
https://git.sr.ht/~cadence/bibliogram
synced 2025-12-16 11:08:49 +00:00
Rewrite feeds
This commit is contained in:
@@ -4,15 +4,29 @@ const {render} = require("pinski/plugins")
|
||||
const {pugCache} = require("../passthrough")
|
||||
|
||||
module.exports = [
|
||||
{route: `/u/(${constants.external.username_regex})/rss.xml`, methods: ["GET"], code: ({fill}) => {
|
||||
{route: `/u/(${constants.external.username_regex})/(rss|atom)\\.xml`, methods: ["GET"], code: ({fill}) => {
|
||||
if (constants.settings.rss_enabled) {
|
||||
const kind = fill[1]
|
||||
return fetchUser(fill[0], true).then(async user => {
|
||||
const content = await user.timeline.fetchFeed()
|
||||
const xml = content.xml()
|
||||
const feed = await user.timeline.fetchFeed()
|
||||
if (kind === "rss") {
|
||||
var data = {
|
||||
contentType: "application/rss+xml", // see https://stackoverflow.com/questions/595616/what-is-the-correct-mime-type-to-use-for-an-rss-feed,
|
||||
content: feed.rss2()
|
||||
}
|
||||
} else if (kind === "atom") {
|
||||
var data = {
|
||||
contentType: "application/atom+xml", // see https://en.wikipedia.org/wiki/Atom_(standard)#Including_in_HTML
|
||||
content: feed.atom1()
|
||||
}
|
||||
}
|
||||
return {
|
||||
statusCode: 200,
|
||||
contentType: "application/rss+xml", // see https://stackoverflow.com/questions/595616/what-is-the-correct-mime-type-to-use-for-an-rss-feed
|
||||
content: xml
|
||||
contentType: data.contentType,
|
||||
headers: {
|
||||
"Cache-Control": `max-age=${userRequestCache.getTtl("user/"+user.data.username, 1000)}`
|
||||
},
|
||||
content: data.content
|
||||
}
|
||||
}).catch(error => {
|
||||
if (error === constants.symbols.NOT_FOUND || error === constants.symbols.ENDPOINT_OVERRIDDEN) {
|
||||
@@ -40,8 +54,8 @@ module.exports = [
|
||||
} else {
|
||||
return Promise.resolve(render(403, "pug/friendlyerror.pug", {
|
||||
statusCode: 403,
|
||||
title: "RSS disabled",
|
||||
message: "RSS is disabled on this instance.",
|
||||
title: "Feeds disabled",
|
||||
message: "Feeds are disabled on this instance.",
|
||||
withInstancesLink: true
|
||||
}))
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ module.exports = [
|
||||
if (typeof page === "number" && !isNaN(page) && page >= 1) {
|
||||
await user.timeline.fetchUpToPage(page - 1)
|
||||
}
|
||||
return render(200, "pug/user.pug", {url, user, constants})
|
||||
return render(200, "pug/user.pug", {url, user, constants, website_origin: constants.website_origin})
|
||||
}).catch(error => {
|
||||
if (error === constants.symbols.NOT_FOUND || error === constants.symbols.ENDPOINT_OVERRIDDEN) {
|
||||
return render(404, "pug/friendlyerror.pug", {
|
||||
|
||||
@@ -8,7 +8,7 @@ html
|
||||
body.homepage
|
||||
header
|
||||
h1.banner
|
||||
img.banner-image(src="/static/img/banner-min.svg")
|
||||
img.banner-image(src="/static/img/banner-min.svg" alt="Bibliogram")
|
||||
.go-sections-container
|
||||
.go-sections
|
||||
section
|
||||
|
||||
9
src/site/pug/includes/feed_link.pug
Normal file
9
src/site/pug/includes/feed_link.pug
Normal file
@@ -0,0 +1,9 @@
|
||||
mixin feed_link(name, urlPart, username, contentType)
|
||||
span
|
||||
a(rel="alternate" type=contentType href=`/u/${username}/${urlPart}.xml`)
|
||||
= name
|
||||
sup.validate-feed
|
||||
-
|
||||
let params = new URLSearchParams()
|
||||
params.set("url", `${website_origin}/u/${username}/${urlPart}.xml`)
|
||||
a(href="https://validator.w3.org/feed/check.cgi?"+params.toString() title="Validate this feed") v!
|
||||
@@ -1,8 +1,9 @@
|
||||
//- Needs user, url, constants
|
||||
//- Needs user, url, constants, website_origin
|
||||
|
||||
include includes/timeline_page.pug
|
||||
include includes/next_page_button.pug
|
||||
include includes/display_structured
|
||||
include includes/feed_link
|
||||
|
||||
- const numberFormat = new Intl.NumberFormat().format
|
||||
|
||||
@@ -19,7 +20,7 @@ html
|
||||
.main-divider
|
||||
header.profile-overview
|
||||
.profile-sticky
|
||||
img(src=user.proxyProfilePicture width="150px" height="150px" alt=`${user.data.full_name || user.data.username}'s profile picture.`).pfp
|
||||
img(src=user.proxyProfilePicture width=150 height=150 alt=`${user.data.full_name || user.data.username}'s profile picture.`).pfp
|
||||
//-
|
||||
Instagram only uses the above URL, but an HD version is also available.
|
||||
The alt text is pathetic, I know. I don't have much to work with.
|
||||
@@ -28,20 +29,23 @@ html
|
||||
h2.username= `@${user.data.username}`
|
||||
else
|
||||
h1.full-name= `@${user.data.username}`
|
||||
if !user.fromReel
|
||||
p.structured-text.bio
|
||||
- const bio = user.getStructuredBio()
|
||||
if bio
|
||||
+display_structured(bio)
|
||||
if user.data.external_url
|
||||
p.website
|
||||
a(href=user.data.external_url)= user.data.external_url
|
||||
p.structured-text.bio
|
||||
- const bio = user.getStructuredBio()
|
||||
if bio
|
||||
+display_structured(bio)
|
||||
if user.data.external_url
|
||||
p.website
|
||||
a(href=user.data.external_url)= user.data.external_url
|
||||
if user.posts != undefined
|
||||
div.profile-counter #[span(data-numberformat=user.posts).count #{numberFormat(user.posts)}] posts
|
||||
if user.following != undefined
|
||||
div.profile-counter #[span(data-numberformat=user.following).count #{numberFormat(user.following)}] following
|
||||
if user.followedBy != undefined
|
||||
div.profile-counter #[span(data-numberformat=user.followedBy).count #{numberFormat(user.followedBy)}] followed by
|
||||
div.links
|
||||
if constants.settings.rss_enabled
|
||||
a(rel="alternate" type="application/rss+xml" href=`/u/${user.data.username}/rss.xml`) RSS
|
||||
+feed_link("RSS", "rss", user.data.username, "application/rss+xml")
|
||||
+feed_link("Atom", "atom", user.data.username, "application/atom+xml")
|
||||
a(rel="noreferrer noopener" href=`https://www.instagram.com/${user.data.username}`) instagram.com
|
||||
|
||||
- const hasPosts = !user.data.is_private && user.timeline.pages.length && user.timeline.pages[0].length
|
||||
|
||||
@@ -102,6 +102,9 @@ body
|
||||
flex-wrap: wrap
|
||||
justify-content: center
|
||||
|
||||
.validate-feed
|
||||
margin-left: 2px
|
||||
|
||||
a, a:visited
|
||||
color: $main-theme-link-color
|
||||
|
||||
|
||||
@@ -21,7 +21,6 @@ subdirs("pug", async (err, dirs) => {
|
||||
pinski.addPugDir("pug", dirs)
|
||||
pinski.addAPIDir("html/static/js/templates/api")
|
||||
pinski.addSassDir("sass")
|
||||
pinski.addAPIDir("api")
|
||||
pinski.muteLogsStartingWith("/imageproxy")
|
||||
pinski.muteLogsStartingWith("/videoproxy")
|
||||
pinski.muteLogsStartingWith("/static")
|
||||
@@ -30,6 +29,7 @@ subdirs("pug", async (err, dirs) => {
|
||||
await require("../lib/utils/tor") // make sure tor state is known before going further
|
||||
}
|
||||
|
||||
pinski.addAPIDir("api")
|
||||
pinski.startServer()
|
||||
pinski.enableWS()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user