Skip to content

Commit

Permalink
Fix download script, use ForkAwesome
Browse files Browse the repository at this point in the history
  • Loading branch information
redtide committed Dec 15, 2023
1 parent 4effb55 commit 94e2048
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 39 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ jobs:
- name: Install Python
uses: actions/setup-python@v4
with:
python-version: 3.x
# FIXME Python 3.12: css_html_js_minify/css_minifier.py:294:
# SyntaxWarning: invalid escape sequence '\.'
python-version: 3.11
- name: Install Poetry
run: python3 -m pip install --upgrade poetry
- name: Cache build data
Expand Down
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
/.bootstrap/
/_site/
/docs/assets/css/*
/docs/assets/js/*
/docs/assets/fonts/
/docs/info/
!/docs/assets/js/color-modes.js
__pycache__/
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ The website is built using the following software and technologies:
- [AnchorJS] anchors headings, MIT license
- [Bootstrap] UI toolkit, code under MIT license, docs under [Creative Commons]
- [Favicon Generator] for favicons
- [Font Awesome] for icons, [SIL OFL 1.1] license
- [Fork Awesome] for icons, [SIL OFL 1.1] license
- [highlight.js] for syntax highlighting, BSD 3-Clause license
- [Markdown] markup language
- [MKDocs] static website generator, BSD-2-Clause license
Expand Down Expand Up @@ -56,6 +56,7 @@ See [LICENSE] file for details.
[Discord]: https://discord.gg/t7nrZ6d
[Favicon Generator]: https://realfavicongenerator.net/
[Font Awesome]: https://fontawesome.io/
[Fork Awesome]: https://forkaweso.me/Fork-Awesome/
[front-matter]: https://www.mkdocs.org/user-guide/writing-your-docs/#meta-data
[highlight.js]: https://highlightjs.org/
[LICENSE]: LICENSE
Expand Down
2 changes: 2 additions & 0 deletions docs/assets/css/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!.gitignore
3 changes: 3 additions & 0 deletions docs/assets/js/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*
!.gitignore
!color-modes.js
7 changes: 4 additions & 3 deletions layout/partials/head.j2
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,17 @@
{% include "partials/favicons.j2" %}
<!-- Stylesheets -->
<link href="{{ 'assets/css/style.min.css'|url }}" rel="stylesheet" media="screen">
<link href="{{ 'assets/css/fork-awesome.min.css'|url }}" rel="stylesheet" media="screen">
<link href="{{ 'assets/css/bootstrap-table.min.css'|url }}" rel="stylesheet">
<link href="{{ 'assets/css/bootstrap-table-filter-control.min.css'|url }}" rel="stylesheet">

{# <link href="{{ 'assets/css/fontawesome.min.css'|url }}" rel="stylesheet" media="screen"> #}
{# <link href="{{ 'assets/css/fontawesome.min.css'|url }}" rel="stylesheet" media="screen"> #}

{%-for style in page.meta.styles-%}
{%- set href = 'assets/css/' + style + '.css' %}
<link href="{{ href|url }}" rel="stylesheet">
{% endfor %}
{%-include "partials/custom-styles.html" %}

{# Disabled, seems having downloading issues elsewhere (GH Actions)
<!-- Font Awesome Icons -->
<script src="{{ 'assets/js/fontawesome.min.js'|url }}"></script>
#}
83 changes: 54 additions & 29 deletions scripts/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"anchor": "4.3.1",
"bootstrap": "5.3.0",
"bootstrap-table": "1.22.1",
"fa": "1.2.0",
"hljs": "11.8.0",
"jquery": "3.6.0",
"popper": "2.11.8"
Expand All @@ -24,62 +25,86 @@ def download_helper(url, path, check=True):
return

print("Downloading " + url + " to " + path)
headers = {"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:101.0) Gecko/20100101 Firefox/101.0"}
headers = {"User-Agent": "Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/114.0"}
response = requests.get(url, headers=headers)
with open(filename, "wb") as file:
file.write(response.content)
file.close()

def download_bootstrap():
bootstrap_test = ".bootstrap/scss/bootstrap.scss"
if os.path.isfile(".bootstrap/scss/bootstrap.scss"):
return

bootstrap_dir = ".bootstrap/bootstrap-" + versions["bootstrap"]
bootstrap_scss = bootstrap_dir + "/scss"
bootstrap_src = "https://github.com/twbs/bootstrap/archive/refs/tags/v" + \
versions["bootstrap"] + ".tar.gz"

if not os.path.isfile(bootstrap_test):
tmp = tempfile.NamedTemporaryFile(delete=False)
try:
download_helper(bootstrap_src, tmp.name, False)
shutil.unpack_archive(tmp.name, ".bootstrap/", "gztar")
shutil.move(bootstrap_scss, ".bootstrap/")
shutil.rmtree(bootstrap_dir)
finally:
tmp.close()
os.unlink(tmp.name)
tmp = tempfile.NamedTemporaryFile(delete=False)
try:
download_helper(bootstrap_src, tmp.name, False)
shutil.unpack_archive(tmp.name, ".bootstrap/", "gztar")
shutil.move(bootstrap_scss, ".bootstrap/")
shutil.rmtree(bootstrap_dir)
finally:
tmp.close()
os.unlink(tmp.name)

def download_forkawesome():
if os.path.isfile("docs/assets/fonts/forkawesome-webfont.ttf"):
return

# fa_url = "https://kit.fontawesome.com/8d25d19870.js"
# fa_path = "docs/assets/js/fontawesome.min.js"
# download_helper(fa_url, fa_path)

fa_zip = versions["fa"] + ".zip"
fa_url = "https://github.com/ForkAwesome/Fork-Awesome/archive/" + fa_zip
fa_dir = "Fork-Awesome-" + versions["fa"]
fa_fnt = fa_dir + "/fonts"
tmp = tempfile.NamedTemporaryFile(delete=False)
try:
download_helper(fa_url, tmp.name, False)
shutil.unpack_archive(tmp.name, ".", "zip")
shutil.move(fa_fnt, "docs/assets/")
shutil.rmtree(fa_dir)
finally:
tmp.close()
os.unlink(tmp.name)

def download():
css_urls = [
"https://cdn.jsdelivr.net/npm/highlight.js@" + versions["hljs"] + "/styles/github.min.css",
"https://cdn.jsdelivr.net/npm/highlight.js@" + versions["hljs"] + "/styles/github-dark-dimmed.min.css",
"https://unpkg.com/bootstrap-table@" + versions["bootstrap-table"] + "/dist/bootstrap-table.min.css"
"https://unpkg.com/bootstrap-table@" + versions["bootstrap-table"] + "/dist/extensions/filter-control/bootstrap-table-filter-control.min.css"
"https://unpkg.com/bootstrap-table@" + versions["bootstrap-table"] + "/dist/bootstrap-table.min.css"
"https://unpkg.com/bootstrap-table@" + versions["bootstrap-table"] + "/dist/extensions/filter-control/bootstrap-table-filter-control.min.css"
"https://cdn.jsdelivr.net/npm/fork-awesome@" + versions["fa"] + "/css/fork-awesome.min.css",
"https://cdn.jsdelivr.net/npm/fork-awesome@" + versions["fa"] + "/css/fork-awesome.min.css.map"
"https://cdn.jsdelivr.net/npm/highlight.js@" + versions["hljs"] + "/styles/github.min.css",
"https://cdn.jsdelivr.net/npm/highlight.js@" + versions["hljs"] + "/styles/github-dark-dimmed.min.css",
]
js_urls = [
"https://unpkg.com/@popperjs/core@" + versions["popper"] + "/dist/umd/popper.min.js",
"https://unpkg.com/@popperjs/core@" + versions["popper"] + "/dist/umd/popper.min.js.map",
"https://unpkg.com/bootstrap-table@" + versions["bootstrap-table"] + "/dist/bootstrap-table.min.js",
"https://unpkg.com/bootstrap-table@" + versions["bootstrap-table"] + "/dist/extensions/filter-control/bootstrap-table-filter-control.min.js",
"https://cdn.jsdelivr.net/npm/jquery@" + versions["jquery"] + "/dist/jquery.min.js",
"https://cdn.jsdelivr.net/npm/jquery@" + versions["jquery"] + "/dist/jquery.min.map",
"https://cdn.jsdelivr.net/npm/anchor-js@" + versions["anchor"] + "/anchor.min.js",
"https://cdn.jsdelivr.net/npm/bootstrap@" + versions["bootstrap"] + "/dist/js/bootstrap.min.js",
"https://cdn.jsdelivr.net/npm/anchor-js@" + versions["anchor"] + "/anchor.min.js",
"https://cdn.jsdelivr.net/npm/bootstrap@" + versions["bootstrap"] + "/dist/js/bootstrap.min.js",
"https://unpkg.com/bootstrap-table@" + versions["bootstrap-table"] + "/dist/bootstrap-table.min.js",
"https://unpkg.com/bootstrap-table@" + versions["bootstrap-table"] + "/dist/extensions/filter-control/bootstrap-table-filter-control.min.js",
"https://cdn.jsdelivr.net/npm/jquery@" + versions["jquery"] + "/dist/jquery.min.js",
"https://cdn.jsdelivr.net/npm/jquery@" + versions["jquery"] + "/dist/jquery.min.map",
"https://unpkg.com/@popperjs/core@" + versions["popper"] + "/dist/umd/popper.min.js",
"https://unpkg.com/@popperjs/core@" + versions["popper"] + "/dist/umd/popper.min.js.map",

"https://cdn.jsdelivr.net/npm/@highlightjs/cdn-assets@" + versions["hljs"] + "/highlight.min.js",
"https://cdn.jsdelivr.net/npm/@highlightjs/cdn-assets@" + versions["hljs"] + "/languages/bash.min.js",
"https://cdn.jsdelivr.net/npm/@highlightjs/cdn-assets@" + versions["hljs"] + "/languages/cpp.min.js",
"https://cdn.jsdelivr.net/gh/sfz/highlight.js@master/dist/sfz.min.js"
]
fa_url = "https://kit.fontawesome.com/8d25d19870.js"
fa_path = "mkdocs/docs/assets/js/fontawesome.min.js"

download_bootstrap()
download_helper(fa_url, fa_path)
download_forkawesome()

path = "mkdocs/docs/assets/css"
path = "docs/assets/css"
for url in css_urls:
download_helper(url, path)

path = "mkdocs/docs/assets/js"
path = "docs/assets/js"
for url in js_urls:
download_helper(url, path)

Expand Down
4 changes: 2 additions & 2 deletions scripts/uglify-assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def silentremove(filename):

def css_compile():
source = ".assets/scss/style.scss"
dest = "mkdocs/docs/assets/css/style.min.css"
dest = "docs/assets/css/style.min.css"

silentremove(dest)
silentremove(dest + ".map")
Expand All @@ -28,7 +28,7 @@ def js_uglify():
sourcedir = ".assets/js/"
for filename in os.listdir(sourcedir):
source = sourcedir + filename
dest = "mkdocs/docs/assets/js/" + os.path.splitext(filename)[0] + ".min.js"
dest = "docs/assets/js/" + os.path.splitext(filename)[0] + ".min.js"
silentremove(dest)
process_single_js_file(source, output_path=dest)

Expand Down

0 comments on commit 94e2048

Please sign in to comment.