add support for wikipagelistings

This commit is contained in:
teddit 2021-04-11 12:10:19 +02:00
parent 22efb3e380
commit b5fe2e1c1f
2 changed files with 41 additions and 10 deletions

View File

@ -943,6 +943,18 @@ module.exports = (app, redis, fetch, RedditAPI) => {
if(!page) if(!page)
page = 'index' page = 'index'
function formatWikipagelisting(json, subreddit) {
let html = '<ul class="wikipagelisting">'
if(json.kind === 'wikipagelisting' && json.data) {
for(var i = 0; i < json.data.length; i++) {
let d = json.data[i]
html += `<li><a href="/r/${subreddit}/wiki/${d}">${d}</a></li>`
}
}
html += '</ul>'
return html
}
let key = `${subreddit.toLowerCase()}:wiki:page:${page}` let key = `${subreddit.toLowerCase()}:wiki:page:${page}`
redis.get(key, (error, json) => { redis.get(key, (error, json) => {
@ -953,11 +965,19 @@ module.exports = (app, redis, fetch, RedditAPI) => {
if(json) { if(json) {
console.log(`Got /r/${subreddit} wiki key from redis.`) console.log(`Got /r/${subreddit} wiki key from redis.`)
json = JSON.parse(json) json = JSON.parse(json)
return res.render('subreddit_wiki', { if(page !== 'pages') {
content_html: unescape(json.data.content_html), return res.render('subreddit_wiki', {
subreddit: subreddit, content_html: unescape(json.data.content_html),
user_preferences: req.cookies subreddit: subreddit,
}) user_preferences: req.cookies
})
} else {
return res.render('subreddit_wiki', {
content_html: formatWikipagelisting(json, subreddit),
subreddit: subreddit,
user_preferences: req.cookies
})
}
} else { } else {
let url = '' let url = ''
if(config.use_reddit_oauth) if(config.use_reddit_oauth)
@ -975,11 +995,19 @@ module.exports = (app, redis, fetch, RedditAPI) => {
return res.render('subreddit', { json: null, user_preferences: req.cookies }) return res.render('subreddit', { json: null, user_preferences: req.cookies })
} else { } else {
console.log(`Fetched the JSON from reddit.com/r/${subreddit}/wiki.`) console.log(`Fetched the JSON from reddit.com/r/${subreddit}/wiki.`)
return res.render('subreddit_wiki', { if(page !== 'pages') {
content_html: unescape(json.data.content_html), return res.render('subreddit_wiki', {
subreddit: subreddit, content_html: unescape(json.data.content_html),
user_preferences: req.cookies subreddit: subreddit,
}) user_preferences: req.cookies
})
} else {
return res.render('subreddit_wiki', {
content_html: formatWikipagelisting(json, subreddit),
subreddit: subreddit,
user_preferences: req.cookies
})
}
} }
}) })
}) })

View File

@ -1452,6 +1452,9 @@ code {
.wiki-content .description h2 { .wiki-content .description h2 {
color:#222 color:#222
} }
.wiki-content ul.wikipagelisting {
padding: 0px 0px 0px 30px;
}
.wiki-content .wikirevisionlisting .generic-table { .wiki-content .wikirevisionlisting .generic-table {
width:100% width:100%
} }