Skip to content

implement minification in in the makefile #67

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 33 additions & 29 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,44 +1,48 @@
EMACS_INIT := /root/.emacs.d/init.el
EMACS_LOAD := -l $(EMACS_INIT)
EMACS_FLAGS := --batch --kill $(EMACS_LOAD)
ORG_FILES := $(wildcard *.org)
HTML_FILES := $(patsubst %.org, %.html, $(ORG_FILES))
DOCKER_IMG := commonlispbr/emacs
USER := $(shell id -u):$(shell id -g)
DOCKER_RUN := docker run -w /tmp \
-v $(shell pwd):/tmp \
--rm \
-t
STATUS_PREFIX := "\033[1;32m[+]\033[0m "
ATTENTION_PREFIX := "\033[1;36m[!]\033[0m "
EMACS_INIT := /root/.emacs.d/init.el
EMACS_LOAD := -l $(EMACS_INIT)
EMACS_FLAGS := --batch --kill $(EMACS_LOAD)
ORG_FILES := $(wildcard *.org)
HTML_FILES := $(patsubst %.org, %.html, $(ORG_FILES))
STATIC_FILES_FOLDER := static/
DOCKER_IMG := commonlispbr/emacs
MINIFY_IMG := tdewolff/minify
USER := $(shell id -u):$(shell id -g)
DOCKER_RUN := docker run -w /tmp \
-v $(shell pwd):/tmp \
--rm \
-t
MINIFY := $(DOCKER_RUN) --entrypoint="/usr/bin/minify" $(MINIFY_IMG)

STATUS_PREFIX := "\033[1;32m[+]\033[0m "

.PHONY: clean shell

all: $(HTML_FILES) copy
all: setup $(HTML_FILES) minify

shell:
$(DOCKER_RUN) -i --entrypoint=/bin/zsh $(DOCKER_IMG)

setup:
@printf $(STATUS_PREFIX); echo "CREATING STATIC FOLDER: $(STATIC_FILES_FOLDER)"
@mkdir -p static

%.html: %.org
@printf $(STATUS_PREFIX); echo "COMPILING: $< -> $*.html"
@$(DOCKER_RUN) $(DOCKER_IMG) $< $(EMACS_FLAGS) -f org-html-export-to-html
@$(DOCKER_RUN) --entrypoint=/bin/chown $(DOCKER_IMG) $(USER) "$*.html"
@mv $*.html $(STATIC_FILES_FOLDER)/$*.html
@printf $(STATUS_PREFIX); echo "MINIFYING: $*.html"
@$(MINIFY) $(STATIC_FILES_FOLDER)/$*.html -o $(STATIC_FILES_FOLDER)/$*.html

copy:
@mkdir -p static
@find . \
"(" -name "*.html" -o -name "*.css" -o -name "*.js" ")" \
-not -path "./static/*" \
-not -path "./.github/*" \
-exec cp {} static \;
@find . \
-name "*.html" \
-not -path "./static/*" \
-not -path "./.github/*" \
-exec mv {} static \;
minify:
@printf $(STATUS_PREFIX); echo "MINIFYING AND BUNDLING CSS FILES"
@$(MINIFY) --bundle org-theme/dist/long/bundle.css css/syntax.css -o $(STATIC_FILES_FOLDER)/long.css
@$(MINIFY) --bundle org-theme/dist/short/bundle.css css/syntax.css -o $(STATIC_FILES_FOLDER)/short.css
@printf $(STATUS_PREFIX); echo "MINIFYING JS FILES"
@$(MINIFY) --bundle org-theme/dist/long/bundle.js -o $(STATIC_FILES_FOLDER)/long.js
@$(MINIFY) --bundle org-theme/dist/long/bundle.js -o $(STATIC_FILES_FOLDER)/short.js

server:
python3 -m http.server 8000 --directory ./static
python3 -m http.server 8000 --directory $(STATIC_FILES_FOLDER)

clean:
rm -rf ./static
rm -rf $(STATIC_FILES_FOLDER)
5 changes: 2 additions & 3 deletions org-theme/setup/long.setup
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,5 @@
# I recommend you to generate your own css/js files by forking, cloning and customizing the file
# theme.json before building it.
#
#+HTML_HEAD: <link rel="stylesheet" type="text/css" href="bundle.css"/>
#+HTML_HEAD: <link rel="stylesheet" type="text/css" href="syntax.css" />
#+HTML_HEAD: <script src="bundle.js" type="text/javascript" ></script>
#+HTML_HEAD: <link rel="stylesheet" type="text/css" href="long.css"/>
#+HTML_HEAD: <script src="long.js" type="text/javascript" ></script>
5 changes: 2 additions & 3 deletions org-theme/setup/short.setup
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,5 @@
# theme.json before building it.
#
#
#+HTML_HEAD: <link rel="stylesheet" type="text/css" href="bundle.css"/>
#+HTML_HEAD: <link rel="stylesheet" type="text/css" href="syntax.css" />
#+HTML_HEAD: <script src="bundle.js" type="text/javascript" ></script>
#+HTML_HEAD: <link rel="stylesheet" type="text/css" href="short.css"/>
#+HTML_HEAD: <script src="short.js" type="text/javascript" ></script>