mirror of
https://github.com/naturalcrit/homebrewery.git
synced 2025-12-24 18:32:41 +00:00
Added sanitizeHtml function to Homebrew model to generate HTML from the brew for the source page.
Moved `source` page generation function to a new function module. Added option to function to create plain text download with a sanitized filename and made it accessible from a new page: `download`. Added the `download` item to the BrewItem so it appears on each brew on the User page. Added `sanitize-filename` dependency to `package.json`.
This commit is contained in:
@@ -34,6 +34,17 @@ HomebrewSchema.methods.sanatize = function(full=false){
|
||||
return brew;
|
||||
};
|
||||
|
||||
HomebrewSchema.methods.sanitizeHtml = function(){
|
||||
const brew = this.toJSON();
|
||||
const replaceStrings = { '&': '&', '<': '<', '>': '>' };
|
||||
text = brew.text;
|
||||
for (const replaceStr in replaceStrings) {
|
||||
text = text.replaceAll(replaceStr, replaceStrings[replaceStr]);
|
||||
}
|
||||
text = `<code><pre style="white-space: pre-wrap;">${text}</pre></code>`;
|
||||
return text;
|
||||
};
|
||||
|
||||
HomebrewSchema.methods.increaseView = async function(){
|
||||
this.lastViewed = new Date();
|
||||
this.views = this.views + 1;
|
||||
|
||||
Reference in New Issue
Block a user