Slide 1

Slide 1 text

Sculpin Static Sites with ddd.io/phptek14-sculpin

Slide 2

Slide 2 text

Beau Simensen @beausimensen +BeauSimensen beau.io

Slide 3

Slide 3 text

Dragonfly Development @dflydev dflydev.com

Slide 4

Slide 4 text

What is a static site generator?

Slide 5

Slide 5 text

STATIC

Slide 6

Slide 6 text

not interpreted

Slide 7

Slide 7 text

every request served directly from the filesystem

Slide 8

Slide 8 text

plain ol' HTML files

Slide 9

Slide 9 text

JavaScript and CSS

Slide 10

Slide 10 text

images

Slide 11

Slide 11 text

JSON, XML, and other supporting files

Slide 12

Slide 12 text

static sites have some advantages

Slide 13

Slide 13 text

less restrictions on hosting environment

Slide 14

Slide 14 text

less moving pieces

Slide 15

Slide 15 text

can more easily absorb traffic spikes

Slide 16

Slide 16 text

more security / less maintenance

Slide 17

Slide 17 text

DyNaMic

Slide 18

Slide 18 text

interpreted at runtime

Slide 19

Slide 19 text

most html is rendered at the time of every request

Slide 20

Slide 20 text

cache can be used to bypass rendering on every request

Slide 21

Slide 21 text

static site generators give you the best of both worlds

Slide 22

Slide 22 text

all of the advantages of static

Slide 23

Slide 23 text

and the power of dynamic

Slide 24

Slide 24 text

Should my next site be static?

Slide 25

Slide 25 text

Should my next site be static? Wrong Question

Slide 26

Slide 26 text

Does my next site need to be dynamic?

Slide 27

Slide 27 text

comments

Slide 28

Slide 28 text

Disqus

Slide 29

Slide 29 text

forms

Slide 30

Slide 30 text

Wufoo

Slide 31

Slide 31 text

Google Forms

Slide 32

Slide 32 text

search

Slide 33

Slide 33 text

lunr.js

Slide 34

Slide 34 text

JavaScript!!!1!

Slide 35

Slide 35 text

if you do not need a dynamic site then a static site may be for you

Slide 36

Slide 36 text

Sculpin?

Slide 37

Slide 37 text

my baby

Slide 38

Slide 38 text

PHP

Slide 39

Slide 39 text

Twig

Slide 40

Slide 40 text

extensible

Slide 41

Slide 41 text

embedded composer

Slide 42

Slide 42 text

SALES PITCH

Slide 43

Slide 43 text

What can Sculpin do?

Slide 44

Slide 44 text

"Can Sculpin do [anything]?"

Slide 45

Slide 45 text

No, not directly... <99% of the time>

Slide 46

Slide 46 text

"How can I do [anything]?"

Slide 47

Slide 47 text

Templates!!!1! <99% of the time>

Slide 48

Slide 48 text

over twenty the number of sculpin sites i've published

Slide 49

Slide 49 text

beau.io dflydev.com sculpin.io srcmvn.com reflxlabsinc.com beausimensen.com stackphp.com thatpodcast.io

Slide 50

Slide 50 text

zero the number of sculpin specific extensions i've written

Slide 51

Slide 51 text

one the number of extensions i've used (i don't use it anymore)

Slide 52

Slide 52 text

So what would you say Sculpin does here?

Slide 53

Slide 53 text

to be honest, not much (remember what I said earlier about my sales pitch?)

Slide 54

Slide 54 text

it reads metadata from sources typically sources are just plain files on disk

Slide 55

Slide 55 text

and site-wide metadata this is maintained in a global configuration file, sculpin_site.yml

Slide 56

Slide 56 text

does hand-wavy stuff with permalinks don't ask...

Slide 57

Slide 57 text

injects everything into a Twig environment

Slide 58

Slide 58 text

and writes rendered output to disk

Slide 59

Slide 59 text

That's it. ok, there is a little more to it than that...

Slide 60

Slide 60 text

you can think of Sculpin as a playground for Twig

Slide 61

Slide 61 text

So how do I use Sculpin?

Slide 62

Slide 62 text

https://sculpin.io/getstarted/ @emmajanehw

Slide 63

Slide 63 text

or jut start small!

Slide 64

Slide 64 text

# mkdir -p source/_layouts # vi source/_layouts/default.html ! {{ page.title }} {% block content %}Fallback content{% endblock %}

Slide 65

Slide 65 text

# 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!

Slide 66

Slide 66 text

sculpin generate --watch --server

Slide 67

Slide 67 text

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.

Slide 68

Slide 68 text

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.

Slide 69

Slide 69 text

No content

Slide 70

Slide 70 text

Where can I see how to do [anything]?

Slide 71

Slide 71 text

Sculpin docs suck. :(

Slide 72

Slide 72 text

people are trying to help make them better @emmajanehw

Slide 73

Slide 73 text

learn by example

Slide 74

Slide 74 text

feeds

Slide 75

Slide 75 text

No content

Slide 76

Slide 76 text

http://thatpodcast.io

Slide 77

Slide 77 text

// source/itunes.xml ! --- use: ["episodes"] permalink: itunes.rss --- That Podcast http://thatpodcast.io

Slide 78

Slide 78 text

// source/itunes.xml ! {% for episode in data.episodes %} Episode {{ episode.number }}: {{ e <itunes:author>Beau Simensen & Dave M {% if episode.subtitle %} <itunes:subtitle>{{ episode.subtitle {% endif %} <itunes:explicit>{{ episode.explicit }}

Slide 79

Slide 79 text

https://github.com/thatpodcast/ thatpodcast.io/

Slide 80

Slide 80 text

search

Slide 81

Slide 81 text

No content

Slide 82

Slide 82 text

http://blog.andrewshell.org/ @andrewshell

Slide 83

Slide 83 text

lunr.js with custom Twig extension @andrewshell

Slide 84

Slide 84 text

// source/search.txt ! --- use: ["posts"] permalink: search.json --- {{ lunr(data.posts) | raw }} @andrewshell

Slide 85

Slide 85 text

https://github.com/andrewshell/ blog.andrewshell.org @andrewshell

Slide 86

Slide 86 text

talks

Slide 87

Slide 87 text

No content

Slide 88

Slide 88 text

https://beau.io/talks/

Slide 89

Slide 89 text

leverages custom content types and does fun stuff with sorting

Slide 90

Slide 90 text

--- title: Static Sites with Sculpin location: "php[tek] 2014" slides: https://speakerdeck.com/simensen/s slides_embed:

Slide 91

Slide 91 text

{% extends "base" %} {% block content %}

{{ page.title }}

{{ page.location }}

{% if page.slides_embed %}
{{ page.slides_embed|raw}}

Slide 92

Slide 92 text

{% 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 %}

Upcoming Talks

Where I will be speaking in the future.

{% set found = true %} {% endif %} {% include "talks_listing_item" %}

Slide 93

Slide 93 text

{% set found = false %} {% for talk in data.talks if talk.date < now %} {% if loop.first %}

Past Talks

Where I have spoken in the past.

{% set found = true %} {% endif %} {% include "talks_listing_item" %} !

Slide 94

Slide 94 text

https://github.com/simensen/ beau.io/

Slide 95

Slide 95 text

authors

Slide 96

Slide 96 text

No content

Slide 97

Slide 97 text

http://dev-human.com/ @erikaheidi

Slide 98

Slide 98 text

leverages site metadata to build and maintain author data @erikaheidi

Slide 99

Slide 99 text

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

Slide 100

Slide 100 text

https://github.com/dev-human/ dev-human/ @erikaheidi

Slide 101

Slide 101 text

projects

Slide 102

Slide 102 text

No content

Slide 103

Slide 103 text

http://dflydev.com/

Slide 104

Slide 104 text

first Sculpin site to leverage custom content types

Slide 105

Slide 105 text

also uses some fun metadata and template tricks to get specific artwork on different pages

Slide 106

Slide 106 text

https://github.com/dflydev/ dflydev.com/

Slide 107

Slide 107 text

external services

Slide 108

Slide 108 text

No content

Slide 109

Slide 109 text

http://cooklufa.seancoates.com/ @coates

Slide 110

Slide 110 text

Twig extension to enable embedding Flickr images @coates

Slide 111

Slide 111 text

{% if page.bg %} 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

Slide 112

Slide 112 text

{{flickr_img('https://www.flickr.com/ photos/scoates/14130067715')}} @coates

Slide 113

Slide 113 text

https://github.com/scoates/ cooklufa/ @coates

Slide 114

Slide 114 text

team directory

Slide 115

Slide 115 text

No content

Slide 116

Slide 116 text

http://reflxlabsinc.com/

Slide 117

Slide 117 text

leverages custom content types

Slide 118

Slide 118 text

https://github.com/reflxlabs/ reflxlabsinc.com/

Slide 119

Slide 119 text

[this page intentionally left blank]

Slide 120

Slide 120 text

Not every site needs to be dynamic

Slide 121

Slide 121 text

Not every site should be static

Slide 122

Slide 122 text

Sculpin is a great choice if you like PHP and Twig

Slide 123

Slide 123 text

Don't expect Sculpin to do anything for you and you'll get along just fine

Slide 124

Slide 124 text

If you love Twig or want to learn it, you'll love Sculpin

Slide 125

Slide 125 text

Get involved in the community!! ! #sculpin

Slide 126

Slide 126 text

Questions? @beausimensen +BeauSimensen joind.in/10658 ddd.io/phptek14-sculpin

Slide 127

Slide 127 text

[this page intentionally left blank]

Slide 128

Slide 128 text

Sculpin metadata.

Slide 129

Slide 129 text

page.[something]

Slide 130

Slide 130 text

--- title: All about metadata --- ! # This is a markdown file with YAML frontmatter

Slide 131

Slide 131 text

--- title: All about metadata --- ! # This is a markdown file with YAML frontmatter

Slide 132

Slide 132 text

--- title: All about metadata --- ! # This is a markdown file with YAML frontmatter {{ page.title }}

Slide 133

Slide 133 text

site.[something]

Slide 134

Slide 134 text

from app/config/sculpin_site.yml

Slide 135

Slide 135 text

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:

Slide 136

Slide 136 text

{% if page.full_title %} {{ page.full_title|raw }} {% else %} {{ page.title }} · {{ site.title }} &middit; {{ site.subtitle }} {% endif %}

Slide 137

Slide 137 text

Sculpin layouts and Twig inheritance.

Slide 138

Slide 138 text

--- layout: default title: All about metadata --- ! # This is a markdown file with YAML frontmatter

Slide 139

Slide 139 text

--- 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 %}

Slide 140

Slide 140 text

--- layout: default title: All about metadata --- ! # This is a markdown file with YAML frontmatter

Slide 141

Slide 141 text

--- layout: default title: All about metadata --- ! # This is a markdown file with YAML frontmatter ! ! {{ page.title }} {% block content %}Fallback content{% endblock %}

Slide 142

Slide 142 text

--- layout: default title: All about metadata --- ! # This is a markdown file with YAML frontmatter ! ! {{ page.title }} {% block content %}Fallback content{% endblock %} ! ! All about metadata

This is a markdown file with YALM frontmatter

Slide 143

Slide 143 text

"Pretty" permalink strategy.

Slide 144

Slide 144 text

source/index.md! becomes output_dev/index.html

Slide 145

Slide 145 text

source/about.md! becomes output_dev/about/index.html

Slide 146

Slide 146 text

source/faq.html! becomes output_dev/faq/index.html