Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Building Static Websites with Sculpin

Oliver Davies
September 07, 2021

Building Static Websites with Sculpin

Oliver Davies

September 07, 2021
Tweet

More Decks by Oliver Davies

Other Decks in Technology

Transcript

  1. What is Sculpin? • Static site generator • CLI tool

    • Built on Symfony's HttpKernel • HTML + Markdown + Twig = Static site @opdavies
  2. What do I use it for? • My personal website

    • Some client websites • HTML prototypes and testing • Learning YAML and Twig (and some Symfony) @opdavies
  3. Configuration • Stored in app/config • sculpin_site.yml • sculpin_site_{env}.yml •

    Key-value pairs --- name: My talk menu_links: - { title: Home, href: / } - { title: About, href: /about } @opdavies
  4. YAML front matter --- layout: post title: New blog post

    draft: yes --- # My new blog post @opdavies
  5. More front matter --- layout: post title: New blog post

    draft: yes tags: - drupal - php - sculpin --- # My new blog post @opdavies
  6. Even more front matter --- layout: post title: New blog

    post draft: yes tags: - drupal - php - sculpin tweets: yes foo: bar --- # My new blog post @opdavies
  7. Using on pages --- ... testimonials: - { name: ...,

    role: ..., text: ..., url: ... } - { name: ..., role: ..., text: ..., url: ... } - { name: ..., role: ..., text: ..., url: ... } --- {% for testimonial in page.testimonials %} <h2>{{ testimonial.name }} - {{ testimonial.role }}</h2> <p>{{ testimonial.text }}</p> {% endfor %} @opdavies
  8. Layouts {# source/_layouts/app.html.twig #} <!DOCTYPE html> <html lang="{{ site.locale|default('en') }}">

    <head> <title>{{ site.name|default('Sculpin Skeleton') }}</title> </head> <body> {% block body %}{% endblock %} </body> </html> @opdavies
  9. Layouts {# source/_layouts/default.html.twig #} {% extends 'app' %} {% block

    body %} {% block content %}{% endblock %} {% endblock %} @opdavies
  10. Includes {% include 'about-author' with { avatar: site.avatar, work: site.work,

    } only %} {% for link in links %} {% include 'menu-link' with { link } only %} {% endfor %} @opdavies
  11. Accessing custom content types --- title: My Projects layout: default

    use: - projects --- {% for project in data.projects %} <h2>{{ project.title }}</h2> {% endfor %} @opdavies
  12. // app/SculpinKernel.php use Opdavies\Sculpin\Bundle\TwigMarkdownBundle\SculpinTwigMarkdownBundle; use Sculpin\Bundle\SculpinBundle\HttpKernel\AbstractKernel; final class SculpinKernel extends

    AbstractKernel { protected function getAdditionalSculpinBundles(): array { return [ SculpinTwigMarkdownBundle::class, ]; } } @opdavies