How Blot works
In essence, Blot is a static file server. It serves your folder to your readers. When a request from one of your readers arrives at your blog, Blot follows these steps to work out what to send in response.
- Check if there is a template whose route matches the request’s path. Render the template if it matches.
- Check if there is a file which matches the request’s path in your blog’s folder. Send the file as a response if it matches.
- Check your site’s list of redirects.
- Render your blog’s error page if it exists, if not render Blot’s error page.
Routing
When a request from one of your readers arrives at your blog, Blot follows these steps to work out what to send in response.
- Check if there is a template whose route matches the request’s path. Render the template if it matches.
- Check if there is a file which matches the request’s path in your blog’s folder. Send the file as a response if it matches.
- Check your site’s list of redirects.
- Render your blog’s error page.
What if a blog post and a file share the same URL?
Blot shows the blog post instead of the file. This is because Blot routes requests from your readers to your blog’s template first. If you prefer, you can disable your blog’s template on the dashboard and just use Blot as a static file server.
Rendering
Blot’s templates are written in Mustache. Consider this example template, which produces a list of all of the posts on your blog:
2
3
4
5
6
7
8
9
10
11
<title>{{title}}</title>
{{#all_posts}}
<a href="{{{url}}}">{{title}}</a><br>
{{/all_posts}}
Blot generates JSON containing the data for this template:
2
3
4
5
6
7
8
9
10
11
{ "title": "Your blog's title", "all_posts": [ {"title": "First post", "url": "/first-post"}, {"title": "Second post", "url": "/second-post"}, {"title": "Third post", "url": "/third-post"} ] }
Blot then renders the template to produce this HTML:
2
3
4
5
6
7
8
9
10
11
<title>Your blog's title</title>
<a href="/first-post">First post</a><br>
<a href="/second-post">Second post</a><br>
<a href="/third-post">Third post</a><br>
Retrieving the JSON used to render a template
If you append the query string ?debug=true
to the URL of any page on your blog, you can see the JSON used to render its template.
Using static files in your templates
Remember that your blog’s folder behaves like a static file server. This makes it possible to share assets between your templates.