diff options
| author | Oxore <oxore@protonmail.com> | 2019-09-29 18:35:42 +0300 | 
|---|---|---|
| committer | Oxore <oxore@protonmail.com> | 2019-09-29 18:35:42 +0300 | 
| commit | 057ccd0a39eaf7ef3c9e6cf3e70044cac14c6bcf (patch) | |
| tree | 3380d4ce978fb308aedc5d7f9a10c20b58cad070 | |
| parent | 891a08d3543c7ee09bc81ba57fe1c8bc0642fe62 (diff) | |
Implement basic template based static page generator
| -rw-r--r-- | .gitignore | 1 | ||||
| -rw-r--r-- | build.py | 43 | ||||
| -rw-r--r-- | oreily-memes.html | 123 | ||||
| -rw-r--r-- | templates/oreily-memes.html.j2 | 22 | 
4 files changed, 66 insertions, 123 deletions
| @@ -1,2 +1,3 @@  *.png  *.jpg +oreily-memes.html diff --git a/build.py b/build.py new file mode 100644 index 0000000..eb9fdbb --- /dev/null +++ b/build.py @@ -0,0 +1,43 @@ +#!/usr/bin/python + +import os +from jinja2 import Template + +def get_memes(directory): +    memes = [] +    files = os.listdir(directory + "/orig/") +    files.sort() +    for f in files: +        meme = { +                "orig": "./{}/orig/{}".format(directory, f), +                "thumb": "./{}/thumb/{}".format(directory, f), +                } +        memes.append(meme) +    return memes + +def bake_thumbnails(memes): +    for meme in memes: +        if not os.access(meme.get("thumb"), os.F_OK): +            os.system("convert {} -resize 320x320^\> {}" +                    .format(meme.get("orig"), meme.get("thumb"))) + +def render_template(template_fname, output_fname, memes): +    template_file = open(template_fname, "r") +    output_file = open(output_fname, "w") +    template = Template(template_file.read()) +    output_file.write(template.render(memes=memes)) +    output_file.close() + + +outdir = "." +memes_dir = "oreily-memes" +# The "om_" prefix means "oreily memes" +om_template_fname = "templates/oreily-memes.html.j2" +om_outdir = outdir +om_output_fname = om_outdir + "/" + "oreily-memes.html" + +if not os.access(outdir, os.F_OK): +    os.mkdir(outdir, int('0775', 8)) +memes = get_memes(memes_dir) +bake_thumbnails(memes) +render_template(om_template_fname, om_output_fname, memes) diff --git a/oreily-memes.html b/oreily-memes.html deleted file mode 100644 index 4cae627..0000000 --- a/oreily-memes.html +++ /dev/null @@ -1,123 +0,0 @@ -<!DOCTYPE html> -<html> -  <head> -    <title>O'Reily Memes</title> -    <style> -      img.meme {width: 24%;} -    </style> -  </head> -  <body> - -    <h1>O'Reily Memes</h1> -    <p> -      <a href=./oreily-memes/orig/banishing-microsoft.jpg> -        <img class=meme src=./oreily-memes/thumb/banishing-microsoft.jpg> -      </a> -      <a href=./oreily-memes/orig/becoming-a-manager.jpg> -        <img class=meme src=./oreily-memes/thumb/becoming-a-manager.jpg> -      </a> -      <a href=./oreily-memes/orig/big-data-little-penis.jpg> -        <img class=meme src=./oreily-memes/thumb/big-data-little-penis.jpg> -      </a> -      <a href=./oreily-memes/orig/coffeeintocode-big.png> -        <img class=meme src=./oreily-memes/thumb/coffeeintocode-big.png> -      </a> -      <a href=./oreily-memes/orig/conding-on-the-weekend.jpg> -        <img class=meme src=./oreily-memes/thumb/conding-on-the-weekend.jpg> -      </a> -      <a href=./oreily-memes/orig/copying-and-pasting-from-stack-overflow.jpg> -        <img class=meme src=./oreily-memes/thumb/copying-and-pasting-from-stack-overflow.jpg> -      </a> -      <a href=./oreily-memes/orig/excuses-for-not-writing-documentation.png> -        <img class=meme src=./oreily-memes/thumb/excuses-for-not-writing-documentation.png> -      </a> -      <a href=./oreily-memes/orig/excuses-for-not-writing-unit-tests.png> -        <img class=meme src=./oreily-memes/thumb/excuses-for-not-writing-unit-tests.png> -      </a> -      <a href=./oreily-memes/orig/exiting-vim.jpg> -        <img class=meme src=./oreily-memes/thumb/exiting-vim.jpg> -      </a> -      <a href=./oreily-memes/orig/fragile-web-development-with-sql-on-rails.png> -        <img class=meme src=./oreily-memes/thumb/fragile-web-development-with-sql-on-rails.png> -      </a> -      <a href=./oreily-memes/orig/getting-an-arduino-led-blink.jpg> -        <img class=meme src=./oreily-memes/thumb/getting-an-arduino-led-blink.jpg> -      </a> -      <a href=./oreily-memes/orig/googling-the-error-message.jpg> -        <img class=meme src=./oreily-memes/thumb/googling-the-error-message.jpg> -      </a> -      <a href=./oreily-memes/orig/hating-on-languages-you-dont-use.png> -        <img class=meme src=./oreily-memes/thumb/hating-on-languages-you-dont-use.png> -      </a> -      <a href=./oreily-memes/orig/hoping-nobody-hacks-you.jpg> -        <img class=meme src=./oreily-memes/thumb/hoping-nobody-hacks-you.jpg> -      </a> -      <a href=./oreily-memes/orig/jpeg-compression.jpg> -        <img class=meme src=./oreily-memes/thumb/jpeg-compression.jpg> -      </a> -      <a href=./oreily-memes/orig/learning-vi.png> -        <img class=meme src=./oreily-memes/thumb/learning-vi.png> -      </a> -      <a href=./oreily-memes/orig/learning-yubnub.jpg> -        <img class=meme src=./oreily-memes/thumb/learning-yubnub.jpg> -      </a> -      <a href=./oreily-memes/orig/lets-put-it-on-the-internet.jpg> -        <img class=meme src=./oreily-memes/thumb/lets-put-it-on-the-internet.jpg> -      </a> -      <a href=./oreily-memes/orig/operations.jpg> -        <img class=meme src=./oreily-memes/thumb/operations.jpg> -      </a> -      <a href=./oreily-memes/orig/practical-unix-internet-security.jpg> -        <img class=meme src=./oreily-memes/thumb/practical-unix-internet-security.jpg> -      </a> -      <a href=./oreily-memes/orig/resolving-broken-dependencies.jpg> -        <img class=meme src=./oreily-memes/thumb/resolving-broken-dependencies.jpg> -      </a> -      <a href=./oreily-memes/orig/rewriting-your-frontend-every-six-weeks.jpg> -        <img class=meme src=./oreily-memes/thumb/rewriting-your-frontend-every-six-weeks.jpg> -      </a> -      <a href=./oreily-memes/orig/shiny-new-things.jpg> -        <img class=meme src=./oreily-memes/thumb/shiny-new-things.jpg> -      </a> -      <a href=./oreily-memes/orig/such-data.jpg> -        <img class=meme src=./oreily-memes/thumb/such-data.jpg> -      </a> -      <a href=./oreily-memes/orig/temporary-workarounds.jpg> -        <img class=meme src=./oreily-memes/thumb/temporary-workarounds.jpg> -      </a> -      <a href=./oreily-memes/orig/the-guy-who-wrote-this-is-gone.jpg> -        <img class=meme src=./oreily-memes/thumb/the-guy-who-wrote-this-is-gone.jpg> -      </a> -      <a href=./oreily-memes/orig/trying-stuff-until-it-works.jpg> -        <img class=meme src=./oreily-memes/thumb/trying-stuff-until-it-works.jpg> -      </a> -      <a href=./oreily-memes/orig/useless-whiteboard-interviews.png> -        <img class=meme src=./oreily-memes/thumb/useless-whiteboard-interviews.png> -      </a> -      <a href=./oreily-memes/orig/web-development-with-assembly.png> -        <img class=meme src=./oreily-memes/thumb/web-development-with-assembly.png> -      </a> -      <a href=./oreily-memes/orig/writing-code-that-nobody-else-can-read.jpg> -        <img class=meme src=./oreily-memes/thumb/writing-code-that-nobody-else-can-read.jpg> -      </a> -      <a href=./oreily-memes/orig/writing-device-drivers-with-javascript.jpg> -        <img class=meme src=./oreily-memes/thumb/writing-device-drivers-with-javascript.jpg> -      </a> -      <a href=./oreily-memes/orig/writing-php-directly-on-the-server.jpg> -        <img class=meme src=./oreily-memes/thumb/writing-php-directly-on-the-server.jpg> -      </a> -      <a href=./oreily-memes/orig/writing-useless-git-commit-messages.jpg> -        <img class=meme src=./oreily-memes/thumb/writing-useless-git-commit-messages.jpg> -      </a> -      <a href=./oreily-memes/orig/z-index-100000000000.jpg> -        <img class=meme src=./oreily-memes/thumb/z-index-100000000000.jpg> -      </a> -    </p> - -    <h1>Related links</h1> -    <p> -      <a href="https://www.reddit.com/r/orlybooks/">r/orlybooks/</a> -    </p> - -  </body> -</html> diff --git a/templates/oreily-memes.html.j2 b/templates/oreily-memes.html.j2 new file mode 100644 index 0000000..b1a8ce0 --- /dev/null +++ b/templates/oreily-memes.html.j2 @@ -0,0 +1,22 @@ +<!DOCTYPE html> +<html> +  <head> +    <title>O'Reily Memes</title> +    <style> +      img.meme {width: 24%;} +    </style> +  </head> +  <body> + +    <h1>O'Reily Memes</h1> +    <p>{% for meme in memes %} +      <a href="{{ meme.orig }}"><img class=meme src="{{ meme.thumb }}"></a>{% endfor %} +    </p> + +    <h1>Related links</h1> +    <p> +      <a href="https://www.reddit.com/r/orlybooks/">r/orlybooks/</a> +    </p> + +  </body> +</html> | 
