add support for wikipagelistings
This commit is contained in:
parent
22efb3e380
commit
b5fe2e1c1f
28
routes.js
28
routes.js
|
@ -944,6 +944,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) => {
|
||||||
if(error) {
|
if(error) {
|
||||||
|
@ -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)
|
||||||
|
if(page !== 'pages') {
|
||||||
return res.render('subreddit_wiki', {
|
return res.render('subreddit_wiki', {
|
||||||
content_html: unescape(json.data.content_html),
|
content_html: unescape(json.data.content_html),
|
||||||
subreddit: subreddit,
|
subreddit: subreddit,
|
||||||
user_preferences: req.cookies
|
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.`)
|
||||||
|
if(page !== 'pages') {
|
||||||
return res.render('subreddit_wiki', {
|
return res.render('subreddit_wiki', {
|
||||||
content_html: unescape(json.data.content_html),
|
content_html: unescape(json.data.content_html),
|
||||||
subreddit: subreddit,
|
subreddit: subreddit,
|
||||||
user_preferences: req.cookies
|
user_preferences: req.cookies
|
||||||
})
|
})
|
||||||
|
} else {
|
||||||
|
return res.render('subreddit_wiki', {
|
||||||
|
content_html: formatWikipagelisting(json, subreddit),
|
||||||
|
subreddit: subreddit,
|
||||||
|
user_preferences: req.cookies
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -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%
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue