mirror of https://github.com/yjwen/org-reveal.git
build: Add caching feature for offline use
Note that fonts will remain online, so caching at browser level or proxy might help. Origin: https://github.com/rzr/rzr-presentations Change-Id: I59ba3e177511fd63b59baccfd97604587766bdb6 Signed-off-by: Philippe Coval <rzr@users.sf.net>
This commit is contained in:
parent
60f6c3a3d2
commit
f058da6fe9
70
Makefile
70
Makefile
|
@ -18,6 +18,8 @@ reveal_zip_url?=https://github.com/hakimel/reveal.js/archive/master.zip
|
||||||
reveal_dir?=./reveal.js
|
reveal_dir?=./reveal.js
|
||||||
sudo?=sudo
|
sudo?=sudo
|
||||||
deploy_branch?=gh-pages
|
deploy_branch?=gh-pages
|
||||||
|
cache_dir?=./cache/url
|
||||||
|
make?=make -f ${CURDIR}/Makefile
|
||||||
|
|
||||||
|
|
||||||
help:
|
help:
|
||||||
|
@ -27,6 +29,7 @@ help:
|
||||||
@echo "# make all # Build html"
|
@echo "# make all # Build html"
|
||||||
@echo "# make start # View HTML in Web browser"
|
@echo "# make start # View HTML in Web browser"
|
||||||
@echo "# make download # Download deps"
|
@echo "# make download # Download deps"
|
||||||
|
@echo "# make offline # Cache inlined resources and generate cached pages"
|
||||||
@echo "# make upload # to build and publish"
|
@echo "# make upload # to build and publish"
|
||||||
@echo "# make setup/debian setup download start # ..."
|
@echo "# make setup/debian setup download start # ..."
|
||||||
@echo "# Config:"
|
@echo "# Config:"
|
||||||
|
@ -131,3 +134,70 @@ upload:
|
||||||
echo "# About to push to origin in 5 secs ?"
|
echo "# About to push to origin in 5 secs ?"
|
||||||
sleep 5 ; git push -f origin HEAD:gh-pages
|
sleep 5 ; git push -f origin HEAD:gh-pages
|
||||||
git checkout master
|
git checkout master
|
||||||
|
|
||||||
|
%.lst: %.org Makefile
|
||||||
|
echo "" > "$@"
|
||||||
|
-grep -o -e 'https\?://[^]"]*' -- "$<" \
|
||||||
|
| grep -E ".**\.(gif|png|svg|jpg|jpeg|webm|mp4)"\
|
||||||
|
| sort -u >> "$@.tmp"
|
||||||
|
mv "$@.tmp" "$@"
|
||||||
|
|
||||||
|
|
||||||
|
%/curl:
|
||||||
|
@mkdir -p http https
|
||||||
|
@ln -fs http http:
|
||||||
|
@ln -fs https https:
|
||||||
|
ls "${@D}" > /dev/null 2>&1 \
|
||||||
|
|| curl --create-dirs -o "./${@D}" -- "${@D}"
|
||||||
|
find . -iname "*#*" | while read file; do \
|
||||||
|
basename=$$(basename -- "$${file}"); \
|
||||||
|
dirname=$$(dirname -- "$${file}"); \
|
||||||
|
dstname=$$(echo "$${basename}" | sed -e 's|#.|%23.|g'); \
|
||||||
|
ln -fs "$${basename}" "$${dirname}/$${dstname}"; \
|
||||||
|
dstname=$$(echo "$${basename}" | sed -e 's|#.||g'); \
|
||||||
|
ln -fs "$${basename}" "$${dirname}/$${dstname}"; \
|
||||||
|
done
|
||||||
|
|
||||||
|
|
||||||
|
.PHONY: cache
|
||||||
|
cache: ${target}.lst Makefile
|
||||||
|
@mkdir -p "${<D}/${cache_dir}"
|
||||||
|
cd "${<D}/${cache_dir}" && \
|
||||||
|
cat "${CURDIR}/$<" | while read url ; do \
|
||||||
|
${make} $${url}/curl || exit $$? ; \
|
||||||
|
done
|
||||||
|
|
||||||
|
|
||||||
|
${target}._cache.org: ${target}.lst ${target}.org cache reveal.js
|
||||||
|
sed -e 's|^#+REVEAL_ROOT:.*|#+REVEAL_ROOT: ${CURDIR}/reveal.js|g' \
|
||||||
|
< ${target}.org > $@.tmp
|
||||||
|
sort -u $< | while read url; do \
|
||||||
|
sed -e "s|$${url}|${cache_dir}/$${url}|g" \
|
||||||
|
-e "s|${cache_dir}/http://|${cache_dir}/http/|g" \
|
||||||
|
-e "s|${cache_dir}/https://|${cache_dir}/https/|g" \
|
||||||
|
-i "${@}.tmp" ; \
|
||||||
|
done
|
||||||
|
mv "${@}.tmp" "$@"
|
||||||
|
|
||||||
|
html-cache: ${target}.org ${target}._cache.org
|
||||||
|
make html target="${target}._cache"
|
||||||
|
sed -e "s|#./|/./|g" -i "${target}._cache.html"
|
||||||
|
|
||||||
|
offline: all/cache all/html-cache
|
||||||
|
sync
|
||||||
|
|
||||||
|
offline/start: offline
|
||||||
|
${MAKE} ${@F} target="${target}._cache"
|
||||||
|
|
||||||
|
commit/offline:
|
||||||
|
-git branch -D ${@F}/master
|
||||||
|
git checkout -b ${@F}/master
|
||||||
|
${MAKE} download
|
||||||
|
-git add -f .
|
||||||
|
-git commit -am 'deploy: Cache downloaded files'
|
||||||
|
${MAKE} cache
|
||||||
|
-git add -f .
|
||||||
|
-git commit -am 'deploy: Cache downloaded files, see lst file for sources'
|
||||||
|
${MAKE} ${@F}
|
||||||
|
-git add -f .
|
||||||
|
-git commit -am 'deploy: Render cached files'
|
||||||
|
|
Loading…
Reference in New Issue