From eded3b59312e57b864819203afeedb6653fa9cf6 Mon Sep 17 00:00:00 2001 From: Michael Persico Date: Tue, 25 Jul 2023 19:12:15 +0000 Subject: [PATCH 01/11] add minify_jll --- Project.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/Project.toml b/Project.toml index 42be4e9bb..667f3b2ad 100644 --- a/Project.toml +++ b/Project.toml @@ -20,6 +20,7 @@ Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" REPL = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb" Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" TOML = "fa267f1f-6049-4f14-aa54-33bafae1ed76" +minify_jll = "7dd700f0-7fa2-5578-8ac1-d309908db794" [compat] DocStringExtensions = "0.8, 0.9" From 0843cd459e783de6e9eed6ec5f80423815b36363 Mon Sep 17 00:00:00 2001 From: Michael Persico Date: Fri, 28 Jul 2023 19:14:47 +0000 Subject: [PATCH 02/11] Remove Python code, unneeded bits --- src/build.jl | 12 ------------ src/manager/post_processing.jl | 11 +---------- src/scripts/minify.py | 29 ----------------------------- test/global/postprocess.jl | 2 -- 4 files changed, 1 insertion(+), 53 deletions(-) delete mode 100644 src/scripts/minify.py diff --git a/src/build.jl b/src/build.jl index 150a476a0..18d7fb816 100644 --- a/src/build.jl +++ b/src/build.jl @@ -82,15 +82,3 @@ function FD_HAS_PY3() end FD_HAS_PIP3() = shell_try(`$([e for e in split(PIP())]) -V`) -function FD_CAN_MINIFY() - r = FD_HAS_PY3() && FD_HAS_PIP3() - r || return r - r = (success(`$([e for e in split(PY())]) -c "import css_html_js_minify"`) || - success(`$([e for e in split(PIP())]) install css_html_js_minify`)) - if !r - @warn """Couldn't find css_html_js_minify (`$([e for e in split(PY())]) -m "import css_html_js_minify"` failed). Will not minify. - - Note: css_html_js_minify is required for minification, but is not necessary to run Franklin (cf docs).""" - end - return r -end diff --git a/src/manager/post_processing.jl b/src/manager/post_processing.jl index 279bab1d8..ee81f1b7b 100644 --- a/src/manager/post_processing.jl +++ b/src/manager/post_processing.jl @@ -100,21 +100,12 @@ function optimize(; # Minification # if minify && (succ || no_fail_prerender) - if FD_CAN_MINIFY() start = time() mmsg = rpad("→ Minifying *.[html|css] files...", 35) print(mmsg) - # copy the script to the current dir - path_to = joinpath(dirname(pathof(Franklin)), - "scripts", "minify.py") - py_script = read(path_to, String) - write(FD_PY_MIN_NAME, py_script) - # run it - succ = success(`$([e for e in split(PY())]) $FD_PY_MIN_NAME`) + # succ = success(`$([e for e in split(PY())]) $FD_PY_MIN_NAME`) # remove the script file - rm(FD_PY_MIN_NAME) print_final(mmsg, start) - end end # if not dev or preview, the /stable/ path was overwritten and we copy that diff --git a/src/scripts/minify.py b/src/scripts/minify.py deleted file mode 100644 index ded231190..000000000 --- a/src/scripts/minify.py +++ /dev/null @@ -1,29 +0,0 @@ -# This is a simple script using `css_html_js_minify` (available via pip) -# to compress html and css files (the js that we use is already compressed). -# This script takes negligible time to run. - -import os -from css_html_js_minify import process_single_html_file as min_html -from css_html_js_minify import process_single_css_file as min_css - -# modify those if you're not using the standard output paths. -html_files = [] -css_files = [] -for root, dirs, files in os.walk("__site"): - for fname in files: - path = os.path.join(root, fname) - # skip the assets folder which should be left untouched (#568) - if path.startswith(os.path.join("__site", "assets")): - continue - if fname.endswith(".html"): - html_files.append(os.path.join(root, fname)) - if fname.endswith(".css"): - css_files.append(os.path.join(root, fname)) - - -css_files = [cf for cf in css_files if not cf.endswith(".min.css")] - -for file in html_files: - min_html(file, overwrite=True) -for file in css_files: - min_css(file, overwrite=True) diff --git a/test/global/postprocess.jl b/test/global/postprocess.jl index 0776c15e9..d76bd6c18 100644 --- a/test/global/postprocess.jl +++ b/test/global/postprocess.jl @@ -24,13 +24,11 @@ @test isfile(joinpath("__site", "css", "franklin.css")) # --------------- - if Franklin.FD_CAN_MINIFY() presize1 = stat(joinpath("__site", "css", "basic.css")).size presize2 = stat(joinpath("__site", "index.html")).size optimize(prerender=false) @test stat(joinpath("__site", "css", "basic.css")).size < presize1 @test stat(joinpath("__site", "index.html")).size < presize2 - end # --------------- # verify all links (XXX) # Franklin.verify_links() From 0bd2332ed59cbdeb424803c209722a109f9a25aa Mon Sep 17 00:00:00 2001 From: Michael Persico Date: Fri, 28 Jul 2023 20:57:38 +0000 Subject: [PATCH 03/11] Integrate minify_jll step --- src/Franklin.jl | 1 + src/manager/post_processing.jl | 8 ++++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Franklin.jl b/src/Franklin.jl index 1d29d60b2..427f4e042 100644 --- a/src/Franklin.jl +++ b/src/Franklin.jl @@ -11,6 +11,7 @@ using OrderedCollections using Pkg using DocStringExtensions: SIGNATURES, TYPEDEF using TOML +using minify_jll import Logging import LiveServer diff --git a/src/manager/post_processing.jl b/src/manager/post_processing.jl index ee81f1b7b..ecf453697 100644 --- a/src/manager/post_processing.jl +++ b/src/manager/post_processing.jl @@ -103,8 +103,12 @@ function optimize(; start = time() mmsg = rpad("→ Minifying *.[html|css] files...", 35) print(mmsg) - # succ = success(`$([e for e in split(PY())]) $FD_PY_MIN_NAME`) - # remove the script file + for (rootpath, _, files) in walkdir("__site") + if rootpath != "__site/assets" + files = filter(endswith(r"^.*\.(html|css|js|json|svg|xml)$"), files) + foreach(file -> success(`$(minify()) -o $(joinpath(rootpath, file)) $(joinpath(rootpath, file))`), files) + end + end print_final(mmsg, start) end From c875c4e1a4b55a79ef7d3d39516867d87474c3c6 Mon Sep 17 00:00:00 2001 From: Michael Persico Date: Fri, 28 Jul 2023 21:18:31 +0000 Subject: [PATCH 04/11] update documentation --- README.md | 3 +-- docs/index.md | 10 ++-------- docs/workflow/index.md | 2 -- src/Franklin.jl | 2 +- 4 files changed, 4 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 581e4aa3e..59a4350b0 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,7 @@ Go to [Franklin's main website](https://franklinjl.org). For users already famil ### Important notes * if, upon deployment, your website doesn't seem to apply CSS, you likely forgot a step, please [see here](https://franklinjl.org/workflow/deploy/#creating_a_repo_on_github). -* it is currently recommended to **switch off** pre-rendering and minification (you can do this by passing `prerender=false, minify=false` to the `optimize(...)` call in your deploy script), the corresponding logic will be removed in future version of Franklin as it's tricky to maintain and caused too many issues. +* it is currently recommended to **switch off** pre-rendering (you can do this by passing `prerender=false` to the `optimize(...)` call in your deploy script), the corresponding logic will be removed in future version of Franklin as it's tricky to maintain and caused too many issues. * if you're getting warning messages about some JS library not being found on your computer, you can safely ignore this. ## Key features @@ -149,5 +149,4 @@ While Franklin broadly supports standard Markdown there are a few things that ma * KaTeX is [MIT licensed](https://github.com/KaTeX/KaTeX/blob/master/LICENSE), * Node's is essentially [MIT licensed](https://github.com/nodejs/node/blob/master/LICENSE), -* css-html-js-minify is [LGPL licensed](https://github.com/juancarlospaco/css-html-js-minify/blob/master/LICENCE.lgpl.txt), * highlight.js is [BSD licensed](https://github.com/highlightjs/highlight.js/blob/master/LICENSE). diff --git a/docs/index.md b/docs/index.md index 63aa0e2e7..4fa0a456e 100644 --- a/docs/index.md +++ b/docs/index.md @@ -54,11 +54,7 @@ You can also inspect the file `menu1.md` which offers more examples of what Fran ## Installing optional extras Franklin allows a post-processing step to compress HTML and CSS and pre-render code blocks and math environments. -This requires a couple of dependencies: -@@tlist -* [`python3`](https://www.python.org/downloads/) for the minification of the site, -* [`node.js`](https://nodejs.org/en/) for the pre-rendering of KaTeX and code highlighting. -@@ +Minifcation is handled via Taco de Wolff's [Minify](https://pkg.go.dev/github.com/tdewolff/Minify/cmd/minify) package, which is already included. Pre-rendering of KaTeX and code highlighting requires [`node.js`](https://nodejs.org/en/) as an installed dependency. You will then need to install `highlight.js`, which you should do from Julia using the [NodeJS.jl](https://github.com/davidanthoff/NodeJS.jl) package: ```julia-repl @@ -68,8 +64,6 @@ julia> run(`sudo $(npm_cmd()) install highlight.js`) **Note**: a key advantage of using `NodeJS` for this instead of using `npm` yourself is that it puts the libraries in the "right place" for Julia to find them. -Assuming you have `python3`, Franklin will try to install the python package [`css_html_js_minify`](https://github.com/juancarlospaco/css-html-js-minify) if via `pip3`. - \note{ - You **don't have to** install these libraries and you can safely ignore any message suggesting you install those. Also note that if you do want this but it doesn't work locally due to some `node` weirdness or related, things will likely still work if you use GitHub to deploy. + You **don't have to** install the external libraries and you can safely ignore any message suggesting you install those. Also note that if you do want this but it doesn't work locally due to some `node` weirdness or related, things will likely still work if you use GitHub to deploy. } diff --git a/docs/workflow/index.md b/docs/workflow/index.md index d81d88e69..e55cac391 100644 --- a/docs/workflow/index.md +++ b/docs/workflow/index.md @@ -179,8 +179,6 @@ Those two steps _may_ lead to faster loading pages. Note that in order to run them, you will need a couple of external dependencies as mentioned in the [installation section](/index.html#installing_optional_extras). \note{ - The minifier script (an external python lib) used is far from perfect and can break your website, generally speaking, if things work locally but not when you deploy, try disabling it with `optimize(minify=false)`. - Also note that if you use GitHub or GitLab pages, the minification is not needed as these platforms compress the pages themselves. } diff --git a/src/Franklin.jl b/src/Franklin.jl index 427f4e042..79baa8dd8 100644 --- a/src/Franklin.jl +++ b/src/Franklin.jl @@ -163,7 +163,7 @@ end # ----------------------------------------------------------------------------- -include("build.jl") # check if user has Node/minify +include("build.jl") # check if user has Node include("regexes.jl") From 8f15fc1b8e47f6fcc48ebc9cd602c6fa8cac5a25 Mon Sep 17 00:00:00 2001 From: Michael Persico Date: Fri, 28 Jul 2023 21:26:56 +0000 Subject: [PATCH 05/11] bump minimum julia version to v1.6 --- Project.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project.toml b/Project.toml index 667f3b2ad..0f5708859 100644 --- a/Project.toml +++ b/Project.toml @@ -32,7 +32,7 @@ LiveServer = "0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0" NodeJS = "0.6, 1" OrderedCollections = "1" TOML = "1.0" -julia = "1.3" +julia = "1.6" [extras] DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0" From 92377acfa14af7937e5abbbf90ac433ea0a48225 Mon Sep 17 00:00:00 2001 From: Michael Persico Date: Fri, 28 Jul 2023 21:29:55 +0000 Subject: [PATCH 06/11] 'installed' to 'external' --- docs/index.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/index.md b/docs/index.md index 4fa0a456e..62aa8d40a 100644 --- a/docs/index.md +++ b/docs/index.md @@ -54,7 +54,7 @@ You can also inspect the file `menu1.md` which offers more examples of what Fran ## Installing optional extras Franklin allows a post-processing step to compress HTML and CSS and pre-render code blocks and math environments. -Minifcation is handled via Taco de Wolff's [Minify](https://pkg.go.dev/github.com/tdewolff/Minify/cmd/minify) package, which is already included. Pre-rendering of KaTeX and code highlighting requires [`node.js`](https://nodejs.org/en/) as an installed dependency. +Minifcation is handled via Taco de Wolff's [Minify](https://pkg.go.dev/github.com/tdewolff/Minify/cmd/minify) package, which is already included. Pre-rendering of KaTeX and code highlighting requires [`node.js`](https://nodejs.org/en/) as an external dependency. You will then need to install `highlight.js`, which you should do from Julia using the [NodeJS.jl](https://github.com/davidanthoff/NodeJS.jl) package: ```julia-repl From 3d191392d6e6a5bdc6b57879a33ae6bad38bb4b2 Mon Sep 17 00:00:00 2001 From: Michael Persico Date: Sat, 29 Jul 2023 15:49:14 +0000 Subject: [PATCH 07/11] attempt post-processing.jl minify fix --- src/manager/post_processing.jl | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/manager/post_processing.jl b/src/manager/post_processing.jl index ecf453697..a5ff714e2 100644 --- a/src/manager/post_processing.jl +++ b/src/manager/post_processing.jl @@ -1,5 +1,3 @@ -const FD_PY_MIN_NAME = ".__py_tmp_minscript.py" - """ $(SIGNATURES) @@ -106,7 +104,13 @@ function optimize(; for (rootpath, _, files) in walkdir("__site") if rootpath != "__site/assets" files = filter(endswith(r"^.*\.(html|css|js|json|svg|xml)$"), files) - foreach(file -> success(`$(minify()) -o $(joinpath(rootpath, file)) $(joinpath(rootpath, file))`), files) + for file in files + filepath = joinpath(rootpath, file) + if !success(`$(minify_jll.minify()) -o $(filepath) $(filepath)`) + succ = false + break + end + end end end print_final(mmsg, start) From 10ec0e981822b4069f98a13001c9748c9932cd6b Mon Sep 17 00:00:00 2001 From: Michael Persico Date: Sun, 30 Jul 2023 22:30:07 +0000 Subject: [PATCH 08/11] Comment out PY/PIP/FD_HAS_PY3 functions + fix highlight.js typo --- src/build.jl | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/build.jl b/src/build.jl index 18d7fb816..84de60865 100644 --- a/src/build.jl +++ b/src/build.jl @@ -1,3 +1,6 @@ +#= +This function currently sits unused, but may prove useful when some future python +dependency may be added for extended Franklin.jl functionality. function PY() if "PYTHON3" ∈ keys(ENV) ENV["PYTHON3"] @@ -12,6 +15,8 @@ function PY() end end end +This function currently sits unused, but may prove useful when some future python +dependency may be added for extended Franklin.jl functionality. function PIP() if "PIP3" ∈ keys(ENV) ENV["PIP3"] @@ -23,6 +28,7 @@ function PIP() end end end +=# function NODE() if "NODE" ∈ keys(ENV) ENV["NODE"] @@ -31,7 +37,7 @@ function NODE() end end -# highligh.js library; can be overridden from the outside which is useful for testing +# highlight.js library; can be overridden from the outside which is useful for testing const HIGHLIGHTJS = Ref{String}("highlight.js") shell_try(com)::Bool = try success(com); catch; false; end @@ -66,11 +72,10 @@ let r = nothing # Hack to only run the checks once per call to Franklin.optimize end #= -Minification -- We use `css_html_js_minify`. To use it, you need python3 and to install it. -- Here we check there is python3, and pip3, and then if we fail to import, we try to +This function currently sits unused, but may prove useful when some future python +dependency may be added for extended Franklin.jl functionality. +Here we check there is python3, and pip3, and then if we fail to import, we try to use pip3 to install it. -=# function FD_HAS_PY3() r = shell_try(`$([e for e in split(PY())]) -V`) if !r @@ -81,4 +86,4 @@ function FD_HAS_PY3() return r end FD_HAS_PIP3() = shell_try(`$([e for e in split(PIP())]) -V`) - +=# From 8850a857f02e853e669805f20e5663cf3ad6bdde Mon Sep 17 00:00:00 2001 From: Michael Persico Date: Sun, 30 Jul 2023 22:36:48 +0000 Subject: [PATCH 09/11] update minify optimize function doc --- src/manager/post_processing.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/manager/post_processing.jl b/src/manager/post_processing.jl index a5ff714e2..ffabbb10f 100644 --- a/src/manager/post_processing.jl +++ b/src/manager/post_processing.jl @@ -14,8 +14,8 @@ Does a full pass followed by a pre-rendering and minification step. not update `/stable/` and `/dev/`. * `prerender=true`: whether to pre-render katex and highlight.js (requires `node.js`) -* `minify=true`: whether to minify output (requires `python3` and - `css_html_js_minify`) +* `minify=true`: whether to minify output (html, css, js, json, svg, and + xml files are supported) * `sig=false`: whether to return an integer indicating success (see [`publish`](@ref)) * `clear=false`: whether to clear the output dir and thereby regenerate From 3fbf15437e54f701080d8d7e96466e3609f113bc Mon Sep 17 00:00:00 2001 From: Michael Persico Date: Sun, 30 Jul 2023 22:43:29 +0000 Subject: [PATCH 10/11] update 'Deploying your website' doc --- docs/workflow/deploy.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/workflow/deploy.md b/docs/workflow/deploy.md index eb77b1e32..f5d266958 100644 --- a/docs/workflow/deploy.md +++ b/docs/workflow/deploy.md @@ -19,8 +19,8 @@ Deploying the website is trivial on an existing web server, via GitHub or Gitlab The contents of the `__site` folder can simply be deployed to a path on an existing server as follows. Supposing you wish your site to appear at `http://my.example.com/path/to/my/franklin/site/`. You would take the following steps: -* Prepare the `__site` directory by running `optimize(prepath="/path/to/my/franklin/site/", minify=false)`. -Franklin.jl does not use relative links, so this step is needed to ensure that the links between site elements are correct. (The `minify = false` argument is optional but is currently recommended.) +* Prepare the `__site` directory by running `optimize(prepath="/path/to/my/franklin/site/")`. +Franklin.jl does not use relative links, so this step is needed to ensure that the links between site elements are correct. * Copy the contents of the `__site` directory to the target location using your chosen method (for example, using [rsync](https://en.wikipedia.org/wiki/Rsync)). From bbf185bb03cb26f281759981d8b68cec04a95593 Mon Sep 17 00:00:00 2001 From: Michael Persico Date: Sun, 30 Jul 2023 23:58:26 +0000 Subject: [PATCH 11/11] fix indent in post_processing.jl --- src/manager/post_processing.jl | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/manager/post_processing.jl b/src/manager/post_processing.jl index ffabbb10f..677d93e44 100644 --- a/src/manager/post_processing.jl +++ b/src/manager/post_processing.jl @@ -98,22 +98,22 @@ function optimize(; # Minification # if minify && (succ || no_fail_prerender) - start = time() - mmsg = rpad("→ Minifying *.[html|css] files...", 35) - print(mmsg) - for (rootpath, _, files) in walkdir("__site") - if rootpath != "__site/assets" - files = filter(endswith(r"^.*\.(html|css|js|json|svg|xml)$"), files) - for file in files - filepath = joinpath(rootpath, file) - if !success(`$(minify_jll.minify()) -o $(filepath) $(filepath)`) - succ = false - break - end + start = time() + mmsg = rpad("→ Minifying *.[html|css] files...", 35) + print(mmsg) + for (rootpath, _, files) in walkdir("__site") + if rootpath != "__site/assets" + files = filter(endswith(r"^.*\.(html|css|js|json|svg|xml)$"), files) + for file in files + filepath = joinpath(rootpath, file) + if !success(`$(minify_jll.minify()) -o $(filepath) $(filepath)`) + succ = false + break end end - end - print_final(mmsg, start) + end + end + print_final(mmsg, start) end # if not dev or preview, the /stable/ path was overwritten and we copy that