Static Sites with Sculpin (php[tek] 2014)

Static Sites with Sculpin (php[tek] 2014)

Already have scaling and caching tools in place, but still concerned about your site's speed? Ever wish you could go back to the days of static sites where page loads were blazing fast but still have the benefits of a dynamic site? Sculpin, a static site generator written in PHP, is a powerful alternative to deploying a PHP website. It dynamically renders your site's content into static files that can be served directly by your webserver saving you execution time on every single page load! Learn more about static site generators in general, discover which types of websites they benefit the most, and learn how to start generating static sites with Sculpin today!

23d971deeb3975a7d28246192fbbe7b7?s=128

Beau Simensen

May 22, 2014
Tweet

Transcript

  1. 5.
  2. 10.
  3. 17.
  4. 27.
  5. 28.
  6. 29.
  7. 30.
  8. 32.
  9. 33.
  10. 35.

    if you do not need a dynamic site then a

    static site may be for you
  11. 36.
  12. 37.
  13. 38.

    PHP

  14. 39.
  15. 64.

    # mkdir -p source/_layouts # vi source/_layouts/default.html ! <html> <head><title>{{

    page.title }}</title></head> {% block content %}Fallback content{% endblock %} </html>
  16. 65.

    # mkdir -p source # vi source/index.md ! --- layout:

    default title: My first Sculpin source --- ! # Hello World! ! Yay! You did it. You created your first [Sculpin](https://sculpin.io) page!
  17. 67.

    Detected new or updated files Generating: 100% (120 sources /

    0.01 seconds) Converting: 100% (120 sources / 0.32 seconds) Formatting: 100% (120 sources / 0.05 seconds) ! ... ! Processing completed in 0.81 seconds Starting Sculpin server for the dev environment with debug true Development server is running at http://localhost:8000 Quit the server with CONTROL-C.
  18. 68.

    Detected new or updated files Generating: 100% (120 sources /

    0.01 seconds) Converting: 100% (120 sources / 0.32 seconds) Formatting: 100% (120 sources / 0.05 seconds) ! ... ! Processing completed in 0.81 seconds Starting Sculpin server for the dev environment with debug true Development server is running at http://localhost:8000 Quit the server with CONTROL-C.
  19. 69.
  20. 74.
  21. 75.
  22. 77.

    // source/itunes.xml ! --- use: ["episodes"] permalink: itunes.rss --- <?xml

    version="1.0" encoding="utf-8"?> <rss xmlns:itunes="http://www.itunes.com/dtds/ <channel> <atom:link href="{{ site.url }}{{ page.url } <title>That Podcast</title> <link>http://thatpodcast.io</link>
  23. 78.

    // source/itunes.xml ! {% for episode in data.episodes %} <item>

    <title>Episode {{ episode.number }}: {{ e <itunes:author>Beau Simensen &amp; Dave M {% if episode.subtitle %} <itunes:subtitle>{{ episode.subtitle {% endif %} <itunes:explicit>{{ episode.explicit }}
  24. 80.
  25. 81.
  26. 86.
  27. 87.
  28. 90.

    --- title: Static Sites with Sculpin location: "php[tek] 2014" slides:

    https://speakerdeck.com/simensen/s slides_embed: <script async class="speaker cover: assets/images/talks/2014-05-22-scul logo: assets/images/talks/tek2014-logo.png logo_link: http://tek.phparch.com/speakers joinedin: https://joind.in/talk/view/10658 tags: - conference
  29. 91.

    {% extends "base" %} {% block content %} <section id="talk"

    class="talk"> <header> <div class="container"> <div class="header-container"> <h1>{{ page.title }}</h1> <p>{{ page.location }}</p> </div> </div> </header> {% if page.slides_embed %} <div class="container slides-player"> <div class="row"> <div class="col-md-8 col-md-offset-2"> {{ page.slides_embed|raw}} </div> </div>
  30. 92.

    <section id="talks"> {% set now = "now"|date_modify("-2 day")|date("U") %} !

    {% set found = false %} {% for talk in data.talks|reverse if talk.date >= now %} {% if loop.first %} <header> <div class="container"> <div class="header-container"> <h1>Upcoming Talks</h1> <p>Where I will be speaking in the future. </div> </div> </header> <div class="container"> {% set found = true %} {% endif %} {% include "talks_listing_item" %}
  31. 93.

    {% set found = false %} {% for talk in

    data.talks if talk.date < now %} {% if loop.first %} <header> <div class="container"> <div class="header-container"> <h1>Past Talks</h1> <p>Where I have spoken in the past. </div> </div> </header> <div class="container"> {% set found = true %} {% endif %} {% include "talks_listing_item" %} !
  32. 95.
  33. 96.
  34. 99.

    authors: erikaheidi: name: Erika Heidi url: http://erikaheidi.com avatar: https://pbs.twimg.com/profile_images/45104284520638 twitter:

    http://twitter.com/erikaheidi googleplus: https://plus.google.com/102734777555057691872 bio: independent web developer && open source enthusiast. s cordoval: name: Luis Cordova url: http://pilotci.com avatar: https://pbs.twimg.com/profile_images/45432988585964 @erikaheidi
  35. 101.
  36. 102.
  37. 105.

    also uses some fun metadata and template tricks to get

    specific artwork on different pages
  38. 108.
  39. 111.

    {% if page.bg %} <style> body:after { content : "";

    display: block; position: fixed; top: 0; left: 0; background: url('{{flickr_url(page.bg, "Large")}}'); background-repeat: no-repeat; background-position: center center; ... @coates
  40. 115.
  41. 130.

    --- title: All about metadata --- ! # This is

    a markdown file with YAML frontmatter
  42. 131.

    --- title: All about metadata --- ! # This is

    a markdown file with YAML frontmatter
  43. 132.

    --- title: All about metadata --- ! # This is

    a markdown file with YAML frontmatter {{ page.title }}
  44. 135.

    title: Dragonfly Development, Inc. (dflydev) google_analytics_tracking_name: dflydev.com google_analytics_tracking_id: setme assets_version:

    6 default_artwork: ninjagrl-seattle artists: ninjagrl: name: ninjagrl url: http://ninjagrl.com tonytaj: name: Tony Taj url: http://tonytaj.com johnosgood: name: John Osgood url: http://johnosgood.com artworks: johnosgood-sitka-pt3:
  45. 136.

    {% if page.full_title %} <title>{{ page.full_title|raw }}</title> {% else %}

    <title> {{ page.title }} &middot; {{ site.title }} &middit; {{ site.subtitle }} </title> {% endif %}
  46. 138.

    --- layout: default title: All about metadata --- ! #

    This is a markdown file with YAML frontmatter
  47. 139.

    --- layout: default title: All about metadata --- ! #

    This is a markdown file with YAML frontmatter ! ! // Sculpin transforms this source file into something that // looks more like this... ! ! {% extends "default" %} {% block content %} ! # This is a markdown file with YAML frontmatter {% endblock %}
  48. 140.

    --- layout: default title: All about metadata --- ! #

    This is a markdown file with YAML frontmatter
  49. 141.

    --- layout: default title: All about metadata --- ! #

    This is a markdown file with YAML frontmatter ! ! <html> <head><title>{{ page.title }}</title></head> {% block content %}Fallback content{% endblock %} </html>
  50. 142.

    --- layout: default title: All about metadata --- ! #

    This is a markdown file with YAML frontmatter ! ! <html> <head><title>{{ page.title }}</title></head> {% block content %}Fallback content{% endblock %} </html> ! ! <html> <head><title>All about metadata</title></head> <h1>This is a markdown file with YALM frontmatter</h1> </html>