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)
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}`
redis.get(key, (error, json) => {
@ -953,11 +965,19 @@ module.exports = (app, redis, fetch, RedditAPI) => {
if(json) {
console.log(`Got /r/${subreddit} wiki key from redis.`)
json = JSON.parse(json)
return res.render('subreddit_wiki', {
content_html: unescape(json.data.content_html),
subreddit: subreddit,
user_preferences: req.cookies
})
if(page !== 'pages') {
return res.render('subreddit_wiki', {
content_html: unescape(json.data.content_html),
subreddit: subreddit,
user_preferences: req.cookies
})
} else {
return res.render('subreddit_wiki', {
content_html: formatWikipagelisting(json, subreddit),
subreddit: subreddit,
user_preferences: req.cookies
})
}
} else {
let url = ''
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 })
} else {
console.log(`Fetched the JSON from reddit.com/r/${subreddit}/wiki.`)
return res.render('subreddit_wiki', {
content_html: unescape(json.data.content_html),
subreddit: subreddit,
user_preferences: req.cookies
})
if(page !== 'pages') {
return res.render('subreddit_wiki', {
content_html: unescape(json.data.content_html),
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 {
color:#222
}
.wiki-content ul.wikipagelisting {
padding: 0px 0px 0px 30px;
}
.wiki-content .wikirevisionlisting .generic-table {
width:100%
}