mirror of
				https://codeberg.org/tacerus/teddit.git
				synced 2025-10-31 19:37:20 +01:00 
			
		
		
		
	add support for wikipagelistings
This commit is contained in:
		
							parent
							
								
									22efb3e380
								
							
						
					
					
						commit
						b5fe2e1c1f
					
				
							
								
								
									
										48
									
								
								routes.js
									
									
									
									
									
								
							
							
						
						
									
										48
									
								
								routes.js
									
									
									
									
									
								
							| @ -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 | ||||
|                     }) | ||||
|                   } | ||||
|                 } | ||||
|               }) | ||||
|             }) | ||||
|  | ||||
| @ -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% | ||||
| } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 teddit
						teddit