mirror of
https://codeberg.org/tacerus/teddit.git
synced 2024-11-25 16:49:26 +01:00
convert reddit.com links to instance domain
This commit is contained in:
parent
7b90601dae
commit
fff9c2d5b9
@ -40,6 +40,12 @@ const config = {
|
||||
shorts: 60 * 60 * 24 * 31,
|
||||
wikis: 60* 60 * 24 * 7
|
||||
},
|
||||
convert_urls: {
|
||||
/**
|
||||
* When enabled, all the domains in the content (e.g. comments, sidebars, wikis etc.) will be replaced with a privacy respecting version.
|
||||
*/
|
||||
reddit: true, // old.reddit.com and reddit.com --> instance domain (config.domain)
|
||||
},
|
||||
valid_media_domains: ['preview.redd.it', 'external-preview.redd.it', 'i.redd.it', 'v.redd.it', 'a.thumbs.redditmedia.com', 'b.thumbs.redditmedia.com', 'emoji.redditmedia.com', 'thumbs.gfycat.com', 'i.ytimg.com'],
|
||||
reddit_api_error_text: `Seems like your instance is either blocked (e.g. due to API rate limiting), reddit is currently down, or your API key is expired and not renewd properly. This can also happen for other reasons.`
|
||||
};
|
||||
|
@ -125,12 +125,15 @@ module.exports = function(request, fs) {
|
||||
}
|
||||
|
||||
this.toUTCString = (time) => {
|
||||
let d = new Date();
|
||||
d.setTime(time*1000);
|
||||
return d.toUTCString();
|
||||
let d = new Date()
|
||||
d.setTime(time*1000)
|
||||
return d.toUTCString()
|
||||
}
|
||||
|
||||
this.unescape = (s) => {
|
||||
/* It would make much more sense to rename this function to something
|
||||
* like "formatter".
|
||||
*/
|
||||
if(s) {
|
||||
var re = /&(?:amp|#38|lt|#60|gt|#62|apos|#39|quot|#34);/g;
|
||||
var unescaped = {
|
||||
@ -145,9 +148,18 @@ module.exports = function(request, fs) {
|
||||
'"': '"',
|
||||
'"': '"'
|
||||
}
|
||||
return s.replace(re, (m) => {
|
||||
return unescaped[m]
|
||||
})
|
||||
if(config.convert_urls.reddit) {
|
||||
let str = s.replace(re, (m) => {
|
||||
return unescaped[m]
|
||||
})
|
||||
let r = new RegExp('((www|old)\.)?reddit.com', 'g')
|
||||
let result = str.replace(r, config.domain)
|
||||
return result
|
||||
} else {
|
||||
return s.replace(re, (m) => {
|
||||
return unescaped[m]
|
||||
})
|
||||
}
|
||||
} else {
|
||||
return ''
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user