You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

overview.md 7.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. +++
  2. title = "Overview"
  3. weight = 5
  4. +++
  5. ## Zola at a Glance
  6. Zola is a static site generator (SSG), similar to [Hugo](https://gohugo.io/), [Pelican](https://blog.getpelican.com/), and [Jekyll](https://jekyllrb.com/) (for a comprehensive list of SSGs, please see the [StaticGen](https://www.staticgen.com/) site). It is written in [Rust](https://www.rust-lang.org/) and uses the [Tera](https://tera.netlify.com/) template engine, which is similar to [Jinja2](https://jinja.palletsprojects.com/en/2.10.x/), [Django templates](https://docs.djangoproject.com/en/2.2/topics/templates/), [Liquid](https://shopify.github.io/liquid/), and [Twig](https://twig.symfony.com/). Content is written in [CommonMark](https://commonmark.org/), a strongly defined, highly compatible specification of [Markdown](https://www.markdownguide.org/).
  7. SSGs use dynamic templates to transform content into static HTML pages. Static sites are thus very fast and require no databases, making them easy to host. A comparison between static and dynamic sites, such as WordPress, Drupal, and Django, can be found [here](https://dev.to/ashenmaster/static-vs-dynamic-sites-61f).
  8. To get a taste of Zola, please see the quick overview below.
  9. ## First Steps with Zola
  10. Unlike some SSGs, Zola makes no assumptions regarding the structure of your site. In this overview, we'll be making a simple blog site.
  11. ### Initialize Site
  12. > This overview is based on Zola 0.9.
  13. Please see the detailed [installation instructions for your platform](@/documentation/getting-started/installation.md). With Zola installed, let's initialize our site:
  14. ```bash
  15. $ zola init myblog
  16. ```
  17. You will be asked a few questions.
  18. ```
  19. > What is the URL of your site? (https://example.com):
  20. > Do you want to enable Sass compilation? [Y/n]:
  21. > Do you want to enable syntax highlighting? [y/N]:
  22. > Do you want to build a search index of the content? [y/N]:
  23. ```
  24. For our blog, let's accept the default values (i.e., press Enter for each question). We now have a `myblog` directory with the following structure:
  25. ```bash
  26. ├── config.toml
  27. ├── content
  28. ├── sass
  29. ├── static
  30. ├── templates
  31. └── themes
  32. ```
  33. Let's start the zola development server with:
  34. ```bash
  35. $ zola serve
  36. Building site...
  37. -> Creating 0 pages (0 orphan), 0 sections, and processing 0 images
  38. ```
  39. > This command must be run in the base Zola directory, which contains `config.toml`.
  40. If you point your web browser to <http://127.0.0.1:1111>, you should see a "Welcome to Zola" message.
  41. ### Home Page
  42. Let's make a home page. To do this, let's first create a `base.html` file inside the `templates` directory. This step will make more sense as we move through this overview. We'll be using the CSS framework [Bulma](https://bulma.io/).
  43. ```html
  44. <!DOCTYPE html>
  45. <html lang="en">
  46. <head>
  47. <meta charset="utf-8">
  48. <title>MyBlog</title>
  49. <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma@0.8.0/css/bulma.min.css">
  50. </head>
  51. <body>
  52. <section class="section">
  53. <div class="container">
  54. {% block content %} {% endblock %}
  55. </div>
  56. </section>
  57. </body>
  58. </html>
  59. ```
  60. Now, let's create an `index.html` file inside the `templates` directory.
  61. ```html
  62. {% extends "base.html" %}
  63. {% block content %}
  64. <h1 class="title">
  65. This is my blog made with Zola.
  66. </h1>
  67. {% endblock content %}
  68. ```
  69. This tells Zola that `index.html` extends our `base.html` file and replaces the block called "content" with the text between the `{% block content %}` and `{% endblock content %}` tags.
  70. ### Content Directory
  71. Now let's add some content. We'll start by making a `blog` subdirectory in the `content` directory and creating an `_index.md` file inside it. This file tells Zola that `blog` is a [section](@/documentation/content/section.md), which is how content is categorized in Zola.
  72. ```bash
  73. ├── content
  74. │ └── blog
  75. │ └── _index.md
  76. ```
  77. In the `_index.md` file, we'll set the following variables in [TOML](https://github.com/toml-lang/toml) format:
  78. ```md
  79. +++
  80. title = "List of blog posts"
  81. sort_by = "date"
  82. template = "blog.html"
  83. page_template = "blog-page.html"
  84. +++
  85. ```
  86. > Note that although no variables are mandatory, the opening and closing `+++` are required.
  87. * *sort_by = "date"* tells Zola to use the date to order our section pages (more on pages below).
  88. * *template = "blog.html"* tells Zola to use `blog.html` in the `templates` directory as the template for listing the Markdown files in this section.
  89. * *page_template = "blog-page.html"* tells Zola to use `blog-page.html` in the `templates` directory as the template for individual Markdown files.
  90. For a full list of section variables, please see the [section](@/documentation/content/section.md) documentation. We will use *title = "List of blog posts"* in a template (see below).
  91. ### Templates
  92. Let's now create some more templates. In the `templates` directory, create a `blog.html` file with the following contents:
  93. ```html
  94. {% extends "base.html" %}
  95. {% block content %}
  96. <h1 class="title">
  97. {{ section.title }}
  98. </h1>
  99. <ul>
  100. {% for page in section.pages %}
  101. <li><a href="{{ page.permalink }}">{{ page.title }}</a></li>
  102. {% endfor %}
  103. </ul>
  104. {% endblock content %}
  105. ```
  106. As done by `index.html`, `blog.html` extends `base.html`, but this time we want to list the blog posts. The *title* we set in the `_index.md` file above is available to us as `{{ section.title }}`. In the list below the title, we loop through all the pages in our section (`blog` directory) and output the page title and URL using `{{ page.title }}` and `{{ page.permalink }}`, respectively. If you go to <http://127.0.0.1:1111/blog/>, you will see the section page for `blog`. The list is empty because we don't have any blog posts. Let's fix that now.
  107. ### Markdown Content
  108. In the `blog` directory, create a file called `first.md` with the following contents:
  109. ```md
  110. +++
  111. title = "My first post"
  112. date = 2019-11-27
  113. +++
  114. This is my first blog post.
  115. ```
  116. The *title* and *date* will be avaiable to us in the `blog-page.html` template as `{{ page.title }}` and `{{ page.date }}`, respectively. All text below the closing `+++` will be available to us as `{{ page.content }}`.
  117. We now need to make the `blog-page.html` template. In the `templates` directory, create this file with the contents:
  118. ```html
  119. {% extends "base.html" %}
  120. {% block content %}
  121. <h1 class="title">
  122. {{ page.title }}
  123. </h1>
  124. <p class="subtitle"><strong>{{ page.date }}</strong></p>
  125. <p>{{ page.content | safe }}</p>
  126. {% endblock content %}
  127. ```
  128. > Note the `| safe` filter for `{{ page.content }}`.
  129. This should start to look familiar. If you now go back to our blog list page at <http://127.0.0.1:1111/blog/>, you should see our lonely post. Let's add another. In the `content/blog` directory, let's create the file `second.md` with the contents:
  130. ```md
  131. +++
  132. title = "My second post"
  133. date = 2019-11-28
  134. +++
  135. This is my second blog post.
  136. ```
  137. Back at <http://127.0.0.1:1111/blog/>, our second post shows up on top of the list because it's newer than the first post and we had set *sort_by = "date"* in our `_index.md` file. As a final step, let's modify our home page to link to our blog posts.
  138. The `index.html` file inside the `templates` directory should be:
  139. ```html
  140. {% extends "base.html" %}
  141. {% block content %}
  142. <h1 class="title">
  143. This is my blog made with Zola.
  144. </h1>
  145. <p>Click <a href="/blog/">here</a> to see my posts.</p>
  146. {% endblock content %}
  147. ```
  148. This has been a quick overview of Zola. You can now dive into the rest of the documentation.