Skip to content

Commit

Permalink
New rendering package (#32)
Browse files Browse the repository at this point in the history
* Updated the `Dockerfile` for the new package
* Updated the GitHub Actions workflow for the new package
  • Loading branch information
carnarez committed Oct 25, 2023
1 parent 85a0306 commit e9ede3d
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 44 deletions.
56 changes: 31 additions & 25 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ jobs:
python -m pip install --no-cache-dir \
ghp-import \
git+https://github.com/carnarez/astdocs@master \
git+https://github.com/carnarez/markdown-astdocs@master \
git+https://github.com/carnarez/markdown-img@master \
git+https://github.com/carnarez/markdown-insert@master \
git+https://github.com/carnarez/markdown-script@master \
git+https://github.com/carnarez/markdown-extension-astdocs@master \
git+https://github.com/carnarez/markdown-extension-img@master \
git+https://github.com/carnarez/markdown-extension-insert@master \
git+https://github.com/carnarez/markdown-extension-script@master \
git+https://github.com/carnarez/markdown-render@master \
jinja2 \
lunr \
markdown \
Expand All @@ -59,33 +60,40 @@ jobs:
(
cd web
# will contain all rendered/bundled content
mkdir www
# where to find the templates (base url)
url=https://raw.githubusercontent.com/carnarez/markdown-render/master
# download the stylesheets
wget $url/style/style.css
wget $url/style/style-highlight.css
wget $url/style/style-markdown.css
wget $url/style/style-search.css
# convert markdown to html
wget $url/build/render.py
wget $url/build/template.html
mkdir /tmp/www
# prepare markdown files
cat front-matter.md index.md > tmp
mv tmp index.md
python render.py --prefix=www --root=https://carnarez.github.io/astdocs/ index.md
rm front-matter.md
# convert markdown to html
render-markdown --prefix=/tmp/www \
--root=https://carnarez.github.io/astdocs/ \
index.md
# prepare html files
# prepare css files
git clone --depth=1 https://github.com/carnarez/markdown-render-styling.git
cat markdown-render-styling/style.css markdown-render-styling/style-*.css | grep -v '@import ".*"' > _bundle.css
cat *.css > /tmp/www/style.css
rm -fr markdown-render-styling *.css
find . -name "*.css" | while read f; do cp $f /tmp/www/$(dirname $f); done
# prepare js files
find . -name "*.js" | while read f; do cp $f /tmp/www/$(dirname $f); done
)
# minify everything
(
cd /tmp/www
# bundle css
cat style.css style-*.css | grep -v '@import ".*"' > www/style.css
find www -name "*.css" | while read f; do
find . -name "*.css" | while read f; do
postcss $f --replace --use autoprefixer
cleancss --output $f $f
done
# bundle html
find www -name "*.html" | while read f; do
find . -name "*.html" | while read f; do
html-minifier --collapse-boolean-attributes \
--collapse-whitespace \
--output $f \
--minify-css true \
--minify-js true \
--output $f \
--remove-attribute-quotes \
--remove-comments \
--remove-empty-attributes \
Expand All @@ -96,15 +104,13 @@ jobs:
--use-short-doctype \
$f
done
# bundle javascript
find . -name "*.js" | while read f; do
terser --compress --mangle --output $f $f
done
# bundle js
find . -name "*.js" | while read f; do terser --compress --mangle --module --output $f $f; done
)
- name: Deploy to https://carnarez.github.io/astdocs/
run: |
(
cd web
ghp-import --branch www --force --push www
ghp-import --branch www --force --push /tmp/www
)
46 changes: 27 additions & 19 deletions web/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,22 @@ FROM python:slim as render

WORKDIR /usr/src

COPY front-matter.md .

RUN apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends --yes git wget \
&& pip install -U pip \
&& pip install --no-cache-dir git+https://github.com/carnarez/astdocs@master \
git+https://github.com/carnarez/markdown-astdocs@master \
git+https://github.com/carnarez/markdown-img@master \
git+https://github.com/carnarez/markdown-insert@master \
git+https://github.com/carnarez/markdown-script@master \
git+https://github.com/carnarez/markdown-extension-astdocs@master \
git+https://github.com/carnarez/markdown-extension-img@master \
git+https://github.com/carnarez/markdown-extension-insert@master \
git+https://github.com/carnarez/markdown-extension-script@master \
git+https://github.com/carnarez/markdown-render@master \
jinja2 \
lunr \
markdown \
pymdown-extensions \
pyyaml \
&& wget --quiet https://raw.githubusercontent.com/carnarez/markdown-render/master/build/render.py \
&& wget --quiet https://raw.githubusercontent.com/carnarez/markdown-render/master/build/template.html
pyyaml

COPY front-matter.md .

RUN wget --quiet https://raw.githubusercontent.com/carnarez/astdocs/master/astdocs/astdocs.py \
&& ASTDOCS_WITH_LINENOS=1 astdocs astdocs.py > index.md \
Expand All @@ -29,7 +28,7 @@ RUN wget --quiet https://raw.githubusercontent.com/carnarez/astdocs/master/astdo
cat front-matter.md $f > /tmp/md; \
mv /tmp/md $f; \
done \
&& python render.py --prefix=/var/www `find . -name "*.md"`
&& render-markdown --prefix=/var/www `find . -name "*.md" | grep -v front-matter.md`


# minify everything in place
Expand All @@ -40,15 +39,21 @@ WORKDIR /var/www

COPY --from=render /var/www .

RUN npm config set update-notifier false \
&& npm install --global --no-audit --no-fund autoprefixer clean-css-cli html-minifier postcss-cli | grep -v ^$ \
&& wget --quiet https://raw.githubusercontent.com/carnarez/markdown-render/master/style/style.css \
&& wget --quiet https://raw.githubusercontent.com/carnarez/markdown-render/master/style/style-highlight.css \
&& wget --quiet https://raw.githubusercontent.com/carnarez/markdown-render/master/style/style-markdown.css \
&& wget --quiet https://raw.githubusercontent.com/carnarez/markdown-render/master/style/style-search.css \
&& cat style.css style-*.css | grep -v '@import ".*"' > bundle.css \
&& mv bundle.css style.css \
&& rm style-*.css \
RUN rm `find . -name "*.md"` \
&& apk --no-cache add git \
&& npm config set update-notifier false \
&& npm install --global --no-audit --no-fund autoprefixer \
clean-css-cli \
html-minifier \
postcss-cli \
terser \
| grep -v ^$ \
&& git clone --depth=1 https://github.com/carnarez/markdown-render-styling.git \
&& cat markdown-render-styling/style.css markdown-render-styling/style-*.css | grep -v '@import ".*"' > _bundle.css \
&& rm -fr markdown-render-styling \
&& cat *.css > bundle.css_ \
&& rm *.css \
&& mv bundle.css_ style.css \
&& find . -name "*.css" | while read f; do \
postcss $f --replace --use autoprefixer; \
cleancss --output $f $f; \
Expand All @@ -68,6 +73,9 @@ RUN npm config set update-notifier false \
--remove-style-link-type-attributes \
--use-short-doctype \
$f; \
done \
&& find . -name "*.js" | while read f; do \
terser --compress --mangle --module --output $f $f; \
done


Expand Down

0 comments on commit e9ede3d

Please sign in to comment.