annotate docs/docs/01_tutorial/01_your-first-blog.md @ 1195:ae9387338db1 draft default tip

admin: add option to publish immediately
author Ludovic Chabant <ludovic@chabant.com>
date Fri, 30 Dec 2022 16:48:04 -0800
parents 70f722a1f447
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
246
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
1 ---
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
2 title: "Part 1: Your First Blog"
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
3 ---
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
4
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
5 This tutorial walks you through the creation of your first PieCrust website: a
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
6 simple blog.
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
7
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
8 > Whenever you see something like this:
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
9 >
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
10 > $ chef blah --something
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
11 >
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
12 > It means you need to run that command (starting with `chef`) in a terminal or
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
13 > command prompt. Text that doesn't start with the dollar sign is the expected
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
14 > output of the command.
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
15
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
16 We'll assume you already have installed PieCrust on your system. If not, the
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
17 installation steps are documented in the ["Getting Started"][1] page.
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
18
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
19 Let's also verify you have an up-to-date version of PieCrust.
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
20
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
21 $ chef --version
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
22 {{piecrust.version}}
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
23
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
24 If your version is older, you'll want to update PieCrust:
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
25
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
26 $ pip install piecrust -U
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
27
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
28 If your version is newer, you're probably looking at old docs! You should be
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
29 able to find newer docs at the [official PieCrust website][2].
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
30
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
31
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
32 ## Create the website
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
33
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
34 Creating the website can be done with a simple command:
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
35
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
36 $ chef init myblog
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
37
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
38 This will create a directory called `myblog` in the current directory, and
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
39 initialize a PieCrust website in it. If you go inside and look at the contents,
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
40 however, you'll be surprised to find that there's not much:
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
41
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
42 $ cd mblog
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
43 $ ls
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
44 config.yml
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
45
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
46 There's just a `config.yml` file! But that's the file that differentiates a
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
47 random directory with a PieCrust website. PieCrust expects a file named like
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
48 that at the root of a website.
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
49
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
50 > Because PieCrust websites are all files (mostly text), they fit really nicely
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
51 > in a source control repository. This makes it so much easier to backup and
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
52 > rollback than with a website running on an SQL database, like Wordpress.
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
53 >
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
54 > It's recommended that you create such a repository right now. If you want to
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
55 > use Git, you would type:
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
56 >
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
57 > $ git init .
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
58 > $ git add .
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
59 > $ git commit -m "Initial empty blog."
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
60 >
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
61 > If you want to use Mercurial, you would type the same commands, but replace
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
62 > `git` with `hg`. For other source control systems, please check the
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
63 > documentation.
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
64 >
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
65 > And of course don't forget to commit your changes as you go!
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
66
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
67
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
68 ## Preview the website
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
69
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
70 At this point, you only have an empty website, but we can still preview it in
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
71 the browser! Type:
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
72
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
73 $ chef serve
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
74 * Running on http://localhost:8080/
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
75
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
76 It should tell you it's started a web server at the address
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
77 `http://localhost:8080`. If you type that in your browser's address bar, you
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
78 should see PieCrust's welcome and boilerplate page.
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
79
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
80 You may notice that the `serve` command is still running. That's because the
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
81 server is still running, which is what you want. You can stop the server by
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
82 hitting `CTRL+C` at any time, but that means the preview won't work anymore. And
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
83 because we still have some work to do, obviously, you'll want to open a new
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
84 terminal or command prompt in order to type new commands.
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
85
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
86 Now let's add some stuff!
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
87
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
88
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
89 ## Add some posts
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
90
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
91 To add posts, you just have to create a text file in the correct place with the
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
92 correct name. By default, PieCrust expects posts in the `posts/` directory,
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
93 with a name like so: `YYYY-MM-DD_title-of-the-post.md`.
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
94
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
95 If you're like me, you probably don't know what today's date is, however. And
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
96 there's also the risk of a typo... so let's instead use the `prepare` command:
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
97
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
98 $ chef prepare post my-first-post
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
99 Creating page: posts/2015-02-19_my-first-post.md
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
100
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
101 There, it tells you the path of the file it created. Open that file now in your
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
102 favorite text editor. You should see something like this:
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
103
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
104 ---
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
105 title: My First Post
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
106 time: '08:21:49'
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
107 ---
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
108
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
109 This is a brand new page.
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
110
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
111 Refresh your browser, and you should see that post instead of the welcome page.
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
112 Edit the post's text (under the second `---` line), and refresh your browser.
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
113
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
114 Now let's add another post. Run the `prepare` command again:
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
115
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
116 $ chef prepare post my-second-post
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
117 Creating page: posts/2015-02-19_my-second-post.md
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
118
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
119 Refresh your browser, and you can see how your blog's homepage is starting to
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
120 shape up as expected, with a reverse-chronological list of your posts. That's
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
121 because the default *theme* for new PieCrust websites defines a page template
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
122 for the home page that does exactly that. This can totally be overriden, of
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
123 course, but it works well as an out-of-the-box experience.
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
124
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
125 If you want to change the title of a post, you can edit the `title:` part in the
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
126 posts' configuration header (which is what we call that part between the 2 `---`
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
127 lines). However, the URL of the post will still have `my-first-post` or
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
128 `my-second-post` in it. If you want to change that, you'd have to rename the
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
129 file itself.
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
130
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
131 > The configuration header is written in [YAML][]. It's usually fairly
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
132 > straightforward, but the first hurdle you may run into is if you want to set a
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
133 > title to something with characters like `'` or `:` in them. In this case,
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
134 > you'll have to add double-quotes (`"`) around the whole thing.
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
135 >
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
136 > If you're using a decent text editor with syntax highlighting, it should know
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
137 > about the YAML syntax and tell you that something's wrong.
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
138
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
139 Similarly, if you want to change the date of a post, you'd have to rename the
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
140 file. The time of the post is in the configuration header, though, so you can
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
141 tweak that in the text file.
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
142
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
143 To know more about the different settings you can change in a page's
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
144 configuration header, check out the [page configuration reference][pageconfref].
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
145
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
146
794
f0fbf218cf44 docs: Tutorial chapter about adding pages.
Ludovic Chabant <ludovic@chabant.com>
parents: 246
diff changeset
147 ## Add some pages
f0fbf218cf44 docs: Tutorial chapter about adding pages.
Ludovic Chabant <ludovic@chabant.com>
parents: 246
diff changeset
148
f0fbf218cf44 docs: Tutorial chapter about adding pages.
Ludovic Chabant <ludovic@chabant.com>
parents: 246
diff changeset
149 Just like posts, pages are text files placed in some specific directory -- the
f0fbf218cf44 docs: Tutorial chapter about adding pages.
Ludovic Chabant <ludovic@chabant.com>
parents: 246
diff changeset
150 appropriately named `pages/` directory. If you create a `pages/foo.md` file,
f0fbf218cf44 docs: Tutorial chapter about adding pages.
Ludovic Chabant <ludovic@chabant.com>
parents: 246
diff changeset
151 you'll get a `/foo.html` page in your published website (or just `/foo` if you
f0fbf218cf44 docs: Tutorial chapter about adding pages.
Ludovic Chabant <ludovic@chabant.com>
parents: 246
diff changeset
152 don't want URLs ending with `.html`).
f0fbf218cf44 docs: Tutorial chapter about adding pages.
Ludovic Chabant <ludovic@chabant.com>
parents: 246
diff changeset
153
f0fbf218cf44 docs: Tutorial chapter about adding pages.
Ludovic Chabant <ludovic@chabant.com>
parents: 246
diff changeset
154 Let's create an "_About_" page for our blog. Once again, we could create the
f0fbf218cf44 docs: Tutorial chapter about adding pages.
Ludovic Chabant <ludovic@chabant.com>
parents: 246
diff changeset
155 text file "by hand" but we can also use the `prepare` command:
f0fbf218cf44 docs: Tutorial chapter about adding pages.
Ludovic Chabant <ludovic@chabant.com>
parents: 246
diff changeset
156
f0fbf218cf44 docs: Tutorial chapter about adding pages.
Ludovic Chabant <ludovic@chabant.com>
parents: 246
diff changeset
157 $ chef prepare page about
f0fbf218cf44 docs: Tutorial chapter about adding pages.
Ludovic Chabant <ludovic@chabant.com>
parents: 246
diff changeset
158 Creating page: pages/about.md
f0fbf218cf44 docs: Tutorial chapter about adding pages.
Ludovic Chabant <ludovic@chabant.com>
parents: 246
diff changeset
159
f0fbf218cf44 docs: Tutorial chapter about adding pages.
Ludovic Chabant <ludovic@chabant.com>
parents: 246
diff changeset
160 Edit that file and change it to something more appropriate... make the title
f0fbf218cf44 docs: Tutorial chapter about adding pages.
Ludovic Chabant <ludovic@chabant.com>
parents: 246
diff changeset
161 something like "_About This Site_", and add some text.
f0fbf218cf44 docs: Tutorial chapter about adding pages.
Ludovic Chabant <ludovic@chabant.com>
parents: 246
diff changeset
162
f0fbf218cf44 docs: Tutorial chapter about adding pages.
Ludovic Chabant <ludovic@chabant.com>
parents: 246
diff changeset
163 You should still have the server running, so type
f0fbf218cf44 docs: Tutorial chapter about adding pages.
Ludovic Chabant <ludovic@chabant.com>
parents: 246
diff changeset
164 `http://localhost:8080/about.html` in the address bar. You should see your new
f0fbf218cf44 docs: Tutorial chapter about adding pages.
Ludovic Chabant <ludovic@chabant.com>
parents: 246
diff changeset
165 page show up.
f0fbf218cf44 docs: Tutorial chapter about adding pages.
Ludovic Chabant <ludovic@chabant.com>
parents: 246
diff changeset
166
f0fbf218cf44 docs: Tutorial chapter about adding pages.
Ludovic Chabant <ludovic@chabant.com>
parents: 246
diff changeset
167 Of course, you probably want a link to that page -- it's not very useful if
f0fbf218cf44 docs: Tutorial chapter about adding pages.
Ludovic Chabant <ludovic@chabant.com>
parents: 246
diff changeset
168 visitors have to know the URL in order to reach it. We could go into layout
f0fbf218cf44 docs: Tutorial chapter about adding pages.
Ludovic Chabant <ludovic@chabant.com>
parents: 246
diff changeset
169 and templating considerations so that we can add it in some kind of sidebar
f0fbf218cf44 docs: Tutorial chapter about adding pages.
Ludovic Chabant <ludovic@chabant.com>
parents: 246
diff changeset
170 menu, but we'll keep this tutorial short for now. Instead, let's just add a link
f0fbf218cf44 docs: Tutorial chapter about adding pages.
Ludovic Chabant <ludovic@chabant.com>
parents: 246
diff changeset
171 to it from one of your blog posts.
f0fbf218cf44 docs: Tutorial chapter about adding pages.
Ludovic Chabant <ludovic@chabant.com>
parents: 246
diff changeset
172
f0fbf218cf44 docs: Tutorial chapter about adding pages.
Ludovic Chabant <ludovic@chabant.com>
parents: 246
diff changeset
173 Open your last created post in a text file, and add something like this:
f0fbf218cf44 docs: Tutorial chapter about adding pages.
Ludovic Chabant <ludovic@chabant.com>
parents: 246
diff changeset
174
f0fbf218cf44 docs: Tutorial chapter about adding pages.
Ludovic Chabant <ludovic@chabant.com>
parents: 246
diff changeset
175 {%raw%}
f0fbf218cf44 docs: Tutorial chapter about adding pages.
Ludovic Chabant <ludovic@chabant.com>
parents: 246
diff changeset
176 You can learn more [about this site here]({{pcurl('about')}})
f0fbf218cf44 docs: Tutorial chapter about adding pages.
Ludovic Chabant <ludovic@chabant.com>
parents: 246
diff changeset
177 {%endraw%}
f0fbf218cf44 docs: Tutorial chapter about adding pages.
Ludovic Chabant <ludovic@chabant.com>
parents: 246
diff changeset
178
f0fbf218cf44 docs: Tutorial chapter about adding pages.
Ludovic Chabant <ludovic@chabant.com>
parents: 246
diff changeset
179 Go back to the home page (`http://localhost:8080`) in your browser and look for
f0fbf218cf44 docs: Tutorial chapter about adding pages.
Ludovic Chabant <ludovic@chabant.com>
parents: 246
diff changeset
180 that new piece of text. It should feature a hyperlink to your new "_About_"
f0fbf218cf44 docs: Tutorial chapter about adding pages.
Ludovic Chabant <ludovic@chabant.com>
parents: 246
diff changeset
181 page.
f0fbf218cf44 docs: Tutorial chapter about adding pages.
Ludovic Chabant <ludovic@chabant.com>
parents: 246
diff changeset
182
f0fbf218cf44 docs: Tutorial chapter about adding pages.
Ludovic Chabant <ludovic@chabant.com>
parents: 246
diff changeset
183 Here's how this worked:
f0fbf218cf44 docs: Tutorial chapter about adding pages.
Ludovic Chabant <ludovic@chabant.com>
parents: 246
diff changeset
184
f0fbf218cf44 docs: Tutorial chapter about adding pages.
Ludovic Chabant <ludovic@chabant.com>
parents: 246
diff changeset
185 * The `[text here](url)` syntax is [Markdown][mdown] for hyperlink. All the
f0fbf218cf44 docs: Tutorial chapter about adding pages.
Ludovic Chabant <ludovic@chabant.com>
parents: 246
diff changeset
186 posts and pages files have a `.md` extension, which means PieCrust will use
f0fbf218cf44 docs: Tutorial chapter about adding pages.
Ludovic Chabant <ludovic@chabant.com>
parents: 246
diff changeset
187 Markdown to format it. This means you can use things like `*asterisks*` and
f0fbf218cf44 docs: Tutorial chapter about adding pages.
Ludovic Chabant <ludovic@chabant.com>
parents: 246
diff changeset
188 `**double asterisks**` to show *italics* and **bold** things. See any
f0fbf218cf44 docs: Tutorial chapter about adding pages.
Ludovic Chabant <ludovic@chabant.com>
parents: 246
diff changeset
189 [Markdown cheat sheet][mdown] to learn about this simple syntax.
f0fbf218cf44 docs: Tutorial chapter about adding pages.
Ludovic Chabant <ludovic@chabant.com>
parents: 246
diff changeset
190
f0fbf218cf44 docs: Tutorial chapter about adding pages.
Ludovic Chabant <ludovic@chabant.com>
parents: 246
diff changeset
191 * As mentioned above, the part in parenthesis is supposed to be the URL of the
f0fbf218cf44 docs: Tutorial chapter about adding pages.
Ludovic Chabant <ludovic@chabant.com>
parents: 246
diff changeset
192 hyperlink, so you might be wondering why we're writing this weird
f0fbf218cf44 docs: Tutorial chapter about adding pages.
Ludovic Chabant <ludovic@chabant.com>
parents: 246
diff changeset
193 {%raw%}`{{pcurl('about')}}`{%endraw%} thing instead of just something like
f0fbf218cf44 docs: Tutorial chapter about adding pages.
Ludovic Chabant <ludovic@chabant.com>
parents: 246
diff changeset
194 `/about.html`.
f0fbf218cf44 docs: Tutorial chapter about adding pages.
Ludovic Chabant <ludovic@chabant.com>
parents: 246
diff changeset
195
f0fbf218cf44 docs: Tutorial chapter about adding pages.
Ludovic Chabant <ludovic@chabant.com>
parents: 246
diff changeset
196 The reason is that a fixed URL is easy to break -- when you change the root
f0fbf218cf44 docs: Tutorial chapter about adding pages.
Ludovic Chabant <ludovic@chabant.com>
parents: 246
diff changeset
197 URL of your site, or when you change between "ugly" URLs (with the `.html`
f0fbf218cf44 docs: Tutorial chapter about adding pages.
Ludovic Chabant <ludovic@chabant.com>
parents: 246
diff changeset
198 extension) and "pretty" URLs (without the extension), along with a few other
f0fbf218cf44 docs: Tutorial chapter about adding pages.
Ludovic Chabant <ludovic@chabant.com>
parents: 246
diff changeset
199 possible changes.
f0fbf218cf44 docs: Tutorial chapter about adding pages.
Ludovic Chabant <ludovic@chabant.com>
parents: 246
diff changeset
200
f0fbf218cf44 docs: Tutorial chapter about adding pages.
Ludovic Chabant <ludovic@chabant.com>
parents: 246
diff changeset
201 The `pcurl` function generates the URL according to the current situation
f0fbf218cf44 docs: Tutorial chapter about adding pages.
Ludovic Chabant <ludovic@chabant.com>
parents: 246
diff changeset
202 and is therefore much more versatile. You can read [more on routing and
f0fbf218cf44 docs: Tutorial chapter about adding pages.
Ludovic Chabant <ludovic@chabant.com>
parents: 246
diff changeset
203 URL functions][routes], or [more on templating in general][tpl].
f0fbf218cf44 docs: Tutorial chapter about adding pages.
Ludovic Chabant <ludovic@chabant.com>
parents: 246
diff changeset
204
f0fbf218cf44 docs: Tutorial chapter about adding pages.
Ludovic Chabant <ludovic@chabant.com>
parents: 246
diff changeset
205
246
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
206 ## Configuring the website
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
207
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
208 This is all fine and dandy, but the big title at the top of the home page still
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
209 says "_My New Website_", and that's not very personal. Let's configure that.
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
210
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
211 Open the `config.yml` file. It's also written in [YAML][], like the posts'
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
212 configuration headers. You can change the `site/title` setting easily:
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
213
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
214 site:
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
215 title: "Ludovic's Blog"
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
216
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
217 > Note how, for the rest of this tutorial (and the rest of the documentation!)
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
218 > we'll refer to nested configuration settings using *slash* separators. So the
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
219 > `site/title` setting refers to the `title` setting inside the `site` setting,
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
220 > as shown in the snippet above.
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
221
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
222 Refresh your browser, and lo and behold, the new title should be there.
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
223
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
224 There are plenty of other things you can configure in the `config.yml` file. For
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
225 example, say you don't like the default URL format for posts. That can be
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
226 adjusted with the `site/post_url` setting. By default, it is:
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
227
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
228 site:
821
70f722a1f447 docs: Add missing quote in example
Raoul Bourquin <raoul@ccczh.ch>
parents: 817
diff changeset
229 post_url: "%year%/%month%/%day%/%slug%"
246
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
230
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
231 The post URL format is defined using some keywords surrounded by percent signs,
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
232 as you can see above. The `%year%`, `%month%` and `%day%` keywords should be
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
233 self-explanatory -- and they map directly to the post's filename, which, if you
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
234 remember, contains the post's date.
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
235
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
236 The `%slug%` keyword maps to the post's "*slug*", which is the [part of the URL
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
237 that has human-readable words][slug]. In PieCrust's case, it comes from the
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
238 part of the filename that comes after the date ("*my-first-post* and
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
239 *my-second-post* in this tutorial).
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
240
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
241 If, say, your blog has a low chance of slug collision, or has a low post
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
242 frequency, and you want to have more minimal URLs, you can change it to:
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
243
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
244 site:
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
245 post_url: "%year%/%slug%"
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
246
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
247 Refresh your browser, and you should see that the posts' URLs are now conforming
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
248 to the new format.
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
249
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
250 > If your browser was currently displaying a post at the old URL, you will
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
251 > suddenly get a "_page not found_" error! That's OK, it's because the post is
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
252 > now at the new, shorter URL. Just go back to the root URL, `localhost:8080`.
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
253
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
254 See the [site configuration reference][siteconfref] for more information about
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
255 all the settings you can change.
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
256
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
257
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
258 ## Next steps
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
259
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
260 At this point you have a moderately function blog, but it's far from looking
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
261 good yet. In the [second part of this tutorial][part2] we'll look at customizing
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
262 your website's appearance by editing layouts and templates, and writing CSS
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
263 stylesheets and using PieCrust's built-in asset pipeline.
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
264
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
265
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
266
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
267 [1]: {{pcurl('getting-started')}}
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
268 [2]: {{piecrust.url}}
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
269 [yaml]: https://en.wikipedia.org/wiki/YAML
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
270 [slug]: http://en.wikipedia.org/wiki/Semantic_URL#Slug
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
271 [pageconfref]: {{pcurl('docs/reference/page-config')}}
817
4cbd534f68b0 docs: Repair some broken links
Raoul Bourquin <raoul@ccczh.ch>
parents: 794
diff changeset
272 [siteconfref]: {{pcurl('docs/reference/website-config')}}
246
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
273 [part2]: {{pcurl('docs/tutorial/making-things-pretty')}}
794
f0fbf218cf44 docs: Tutorial chapter about adding pages.
Ludovic Chabant <ludovic@chabant.com>
parents: 246
diff changeset
274 [routes]: {{docurl('content-model/routes')}}
f0fbf218cf44 docs: Tutorial chapter about adding pages.
Ludovic Chabant <ludovic@chabant.com>
parents: 246
diff changeset
275 [tpl]: {{docurl('content/templating')}}
f0fbf218cf44 docs: Tutorial chapter about adding pages.
Ludovic Chabant <ludovic@chabant.com>
parents: 246
diff changeset
276 [mdown]: http://commonmark.org/help/
246
afc1d2c60854 docs: Tutorial part 1.
Ludovic Chabant <ludovic@chabant.com>
parents:
diff changeset
277