Strip scripts

This commit is contained in:
octospacc 2022-07-18 17:16:21 +02:00
parent ee981f2d57
commit 7ac41b2884
3 changed files with 22 additions and 5 deletions

19
Source/Modules/HTML.py Normal file
View File

@ -0,0 +1,19 @@
""" ================================= |
| This file is part of |
| staticoso |
| Just a simple Static Site Generator |
| |
| Licensed under the AGPLv3 license |
| Copyright (C) 2022, OctoSpacc |
| ================================= """
from Libs.bs4 import BeautifulSoup
from Modules.Utils import *
def StripTags(HTML, ToStrip):
Soup = BeautifulSoup(HTML, 'html.parser')
Tags = Soup.find_all()
for t in Tags:
if t.name in ToStrip:
t.replace_with('')
return str(Soup)

View File

@ -9,6 +9,7 @@
from Libs import htmlmin
from Libs.bs4 import BeautifulSoup
from Modules.HTML import *
from Modules.Markdown import *
from Modules.Pug import *
from Modules.Utils import *
@ -403,10 +404,7 @@ def MakeSite(TemplatesText, PartsText, ContextParts, ContextPartsText, ConfMenu,
SiteLang=SiteLang,
Locale=Locale)
if NoScripts:
HTML = (HTML
).replace('<script>', '<!-- script >'
).replace('<script ', '<!-- script '
).replace('</script>', '</ script -->')
HTML = StripTags(HTML, ['script'])
if Minify:
HTML = DoMinifyHTML(HTML)
WriteFile(PagePath, HTML)

2
TODO
View File

@ -1,2 +1,2 @@
- ActivityPub: Only post "Blog" posts and not older than some date
- Fix some CLI arguments stuff
- Fix arguments - some are only callable from CLI and not Site.ini