Static Sites in Python

A presentation at CLEpy in March 2019 in Cleveland, OH, USA by Zach Passen

Slide 1

Slide 1

Static Sites In Python Kat Passen 1

Slide 2

Slide 2

Before we begin • Taxonomy - classification scheme • Tag - metadata used to classify content • SSG - static site generator • CMS - content management system 2

Slide 3

Slide 3

“what is a static site” 3

Slide 4

Slide 4

“what is a static site” => “what is JAMstack” 4

Slide 5

Slide 5

JAMstack • JavaScript • APIs • Markup 5

Slide 6

Slide 6

🤔 6

Slide 7

Slide 7

What is not JAMstack • Traditional server setup (Django) • CMS-based site • Single Page Application 7

Slide 8

Slide 8

Why JAMstack • Pages generated at deploy time, not during request • All files (including HTML!) can live on CDN • Can use a CMS alongside a JAMstack site: consolidate your stacks • All server-side processes are micro services 8

Slide 9

Slide 9

What is a static site • HTML page with prepopulated content • https://www.staticgen.com/ 9

Slide 10

Slide 10

In this talk: • Lektor • Statik • Pelican • Not things like Sphinx 10

Slide 11

Slide 11

Lektor https://www.getlektor.com/ 11

Slide 12

Slide 12

Lektor - Intro • Partway between SSG and CMS • Aimed more towards CMS-style content, but without the CMS server • WYSIWYG editing with HTML output 12

Slide 13

Slide 13

Lektor - Setup $ curl -sf https://www.getlektor.com/ install.sh | sh 13

Slide 14

Slide 14

🤔😬😩 14

Slide 15

Slide 15

/usr/bin/ruby -e “$(curl -fsSL https:// raw.githubusercontent.com/Homebrew/ install/master/install)” 15

Slide 16

Slide 16

$ pip install pelican $ brew install hugo $ gem install bundler jekyll $ npm install —save-dev @11ty/eleventy … $ curl -sf https://www.getlektor.com/ install.sh | sh 16

Slide 17

Slide 17

Statik https://getstatik.com/ 17

Slide 18

Slide 18

Statik - Intro • Non-blog oriented SSG • “what if Hugo but custom data models” (SQLAlchemy) • Jinja2 templates 18

Slide 19

Slide 19

Statik - Setup $ python3 -m venv path/to/stuff/; source venv/bin/activate $ statik —quickstart (make some views) $ statik —watch 19

Slide 20

Slide 20

Statik - Detail • Quickstart just kind of leaves you hanging • Models and views are defined as YAML, data is defined as either YAML or Markdown • In your data, you can refer to model instances by primary key to autofill info • Dynamic variables in views are just database queries • Themes are separate: https://github.com/thanethomson/ statik-themes 20

Slide 21

Slide 21

Statik - Detail 21

Slide 22

Slide 22

Statik - Detail 22

Slide 23

Slide 23

Statik - Results 23

Slide 24

Slide 24

Pelican https://blog.getpelican.com/ 24

Slide 25

Slide 25

Pelican - Intro • Extremely blog-oriented - category taxonomy, chronological content • “Pages” - non-content pages (about, contact) • Content is reStructuredText or Markdown 25

Slide 26

Slide 26

Pelican - Intro • i18n support (thru plugins) • Jinja2 templates • Integrates with various third-party services (thru plugins) 26

Slide 27

Slide 27

Pelican - Demo 27