Skip to content

Commit

Permalink
Merge pull request #28 from cmason3/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
cmason3 authored Dec 12, 2023
2 parents 3925664 + a37a4fd commit 51437ac
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 31 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2020-2023 Chris Mason (chris@netnix.org)
Copyright (c) 2020-2024 Chris Mason (chris@netnix.org)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
56 changes: 31 additions & 25 deletions contrib/update_cdnjs_links.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,42 +10,48 @@
'js-yaml': '4.1.0',
'dayjs': '1.11.10',
'pako': '2.1.0',
'jszip': '3.10.1'
'jszip': '3.10.1',
'github-markdown-css': '5.5.0'
}

def update_file(cdnjs_url, sri, f):
data = []

with open(f, 'rt') as fh:
for ln in fh.readlines():
if m := cdnjs_url.search(ln):
if m.group(2) in sri:
if m.group(1) != libraries[lib]:
ln = cdnjs_url.sub('https://cdnjs.cloudflare.com/ajax/libs/' + lib + '/' + libraries[lib] + '/' + m.group(2) + '"', ln)
ln = re.sub(r'integrity=".+?"', 'integrity="' + sri[m.group(2)] + '"', ln)
print(os.path.basename(f) + ' - updated ' + lib + '/' + m.group(2) + ' to ' + libraries[lib])

else:
print(os.path.basename(f) + ' - skipping ' + lib + '/' + m.group(2) + ' - already at ' + libraries[lib])

else:
print('warning: can\'t find resource "' + m.group(2) + '" on cdnjs', file=sys.stderr)

data.append(ln)

if len(data) > 0:
with open(f, 'wt') as fh:
fh.writelines(data)


for lib in libraries:
www = os.path.normpath(os.path.dirname(os.path.abspath(__file__)) + '/../www')
www = os.path.normpath(os.path.dirname(os.path.abspath(__file__)) + '/../www/')
cdnjs = re.compile(r'https://cdnjs.cloudflare.com/ajax/libs/' + re.escape(lib) + '/(.+?)/(.+?)"')

api_url = 'https://api.cdnjs.com/libraries/' + lib + '/' + libraries[lib]
r = requests.get(api_url + '?fields=sri').json()

if 'sri' in r:
update_file(cdnjs, r['sri'], os.path.normpath(os.path.dirname(os.path.abspath(__file__)) + '/../jinjafx_server.py'))

for fn in os.listdir(www):
if fn.endswith('.html'):
html = []

with open(www + '/' + fn, 'rt') as fh:
for ln in fh.readlines():
m = cdnjs.search(ln)
if m:
if m.group(2) in r['sri']:
if m.group(1) != libraries[lib]:
ln = cdnjs.sub('https://cdnjs.cloudflare.com/ajax/libs/' + lib + '/' + libraries[lib] + '/' + m.group(2) + '"', ln)
ln = re.sub(r'integrity=".+?"', 'integrity="' + r['sri'][m.group(2)] + '"', ln)
print(fn + ' - updated ' + lib + '/' + m.group(2) + ' to ' + libraries[lib])

else:
print(fn + ' - skipping ' + lib + '/' + m.group(2) + ' - already at ' + libraries[lib])

else:
print('warning: can\'t find resource "' + m.group(2) + '" on cdnjs', file=sys.stderr)

html.append(ln)

if len(html) > 0:
with open(www + '/' + fn, 'wt') as fh:
fh.writelines(html)
update_file(cdnjs, r['sri'], www + '/' + fn)

elif 'error' in r:
print('error: ' + r['message'], file=sys.stderr)
Expand Down
8 changes: 4 additions & 4 deletions jinjafx_server.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python3

# JinjaFx Server - Jinja2 Templating Tool
# Copyright (c) 2020-2023 Chris Mason <chris@netnix.org>
# Copyright (c) 2020-2024 Chris Mason <chris@netnix.org>
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
Expand All @@ -28,7 +28,7 @@
import re, argparse, hashlib, traceback, glob, hmac, uuid, struct, binascii, gzip, requests, ctypes, subprocess
import cmarkgfm, emoji

__version__ = '23.12.0'
__version__ = '23.12.1'

llock = threading.RLock()
rlock = threading.RLock()
Expand Down Expand Up @@ -548,7 +548,7 @@ def html_escape(text):
options = (cmarkgfm.cmark.Options.CMARK_OPT_GITHUB_PRE_LANG | cmarkgfm.cmark.Options.CMARK_OPT_SMART | cmarkgfm.cmark.Options.CMARK_OPT_UNSAFE)
output = cmarkgfm.github_flavored_markdown_to_html(html_escape(output), options).replace('&amp;amp;', '&amp;').replace('&amp;', '&')
head = '<!DOCTYPE html>\n<html>\n<head>\n'
head += '<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/github-markdown-css/5.3.0/github-markdown.min.css" crossorigin="anonymous">\n'
head += '<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/github-markdown-css/5.5.0/github-markdown.min.css" crossorigin="anonymous">\n'
head += '<style>\n pre, code { white-space: pre-wrap !important; word-wrap: break-word !important; }\n</style>\n</head>\n'
output = emoji.emojize(output, language='alias').encode('ascii', 'xmlcharrefreplace').decode('utf-8')
output = head + '<body>\n<div class="markdown-body">\n' + output + '</div>\n</body>\n</html>\n'
Expand Down Expand Up @@ -922,7 +922,7 @@ def main(rflag=[0]):

try:
print('JinjaFx Server v' + __version__ + ' - Jinja2 Templating Tool')
print('Copyright (c) 2020-2023 Chris Mason <chris@netnix.org>\n')
print('Copyright (c) 2020-2024 Chris Mason <chris@netnix.org>\n')

update_versioned_links(base + '/www')

Expand Down
2 changes: 1 addition & 1 deletion jinjafx_server/__main__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env python3

# JinjaFx Server - Jinja2 Templating Tool
# Copyright (c) 2020-2023 Chris Mason <chris@netnix.org>
# Copyright (c) 2020-2024 Chris Mason <chris@netnix.org>
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
Expand Down

0 comments on commit 51437ac

Please sign in to comment.