Skip to content

Instantly share code, notes, and snippets.

@dustinlacewell-wk
Created September 2, 2017 01:15
Show Gist options
  • Save dustinlacewell-wk/161e822542812d468c53fdbfd7037a2f to your computer and use it in GitHub Desktop.
Save dustinlacewell-wk/161e822542812d468c53fdbfd7037a2f to your computer and use it in GitHub Desktop.
import blot
from blot.utils import generate_cloud
from blot.loaders import BasicLoader, SassLoader
from blot.writers import ListWriter, IndexWriter, StaticWriter, PaginatedWriter
from blot.processors import (
PathMetadata, YAMLMetadata,
AutoSummary, Titler, Slugifier, Humanizer,
Tags, Categories, CategoryTags, Series, SeriesTags,
MarkdownParser, JinjaRenderer, CssMinify)
# static top-level rendering context
base_context = dict(
SITE_TITLE="ldlework.com",
SITE_SUBTITLE="Most of this is probably made up",
TEMPLATE_PATH="theme/templates",
SOCIAL_LINKS=(
('email', '[email protected]'),
('github', 'http://github.com/dustinlacewell')),
TAGCLOUD=generate_cloud, # generates clouds from lists of Aggregates
)
# content types definitions specify where to find content sources and how to
# parse and process them into rich asset objects
content_types = dict(
posts={
'loader': BasicLoader('content/posts', extensions=['md']),
'processors': [
YAMLMetadata(),
# add metadata derived from source path
PathMetadata(),
# create a title from the parent directory name
Titler('parent'),
# create a slug from the `title` property
Slugifier('title'),
# humanize the `date` property
Humanizer('date'),
# aggregate assets across their `tags` property
Tags(),
# aggregate assets across their `category` property which is
# derived from the second parent directory
Categories('dirname', '([^/]*)/[^/]*$'),
# aggregate categories by tag
CategoryTags(),
# aggregate assets across their `series` property
Series(),
# aggregate series by tag
SeriesTags(),
],
'finalizers': [
JinjaRenderer(),
MarkdownParser(),
# generate a summary from content
AutoSummary(),
],
},
sass={
'loader': SassLoader('theme/sass/main.scss',
compress=False,
paths=['/normalize/sass',
'/typey/stylesheets']),
'finalizers': [CssMinify()],
},
pages={
'loader': BasicLoader('content/pages', extensions=['md']),
'processors': [
YAMLMetadata(),
PathMetadata(),
],
'finalizers': [
JinjaRenderer(),
MarkdownParser(),
]
},
# load image content
pageimages={
'loader': BasicLoader('content/pages', extensions=['png', 'jpg', 'gif', 'bmp']),
'processors': [
PathMetadata()
],
},
# load image content
postimages={
'loader': BasicLoader('content/posts', extensions=['png', 'jpg', 'gif', 'bmp']),
'processors': [
PathMetadata()
],
},
# load css files from the theme
staticfiles={
'loader': BasicLoader('theme/static', extensions=['css', 'svg']),
'processors': [
PathMetadata()
],
})
def build():
context = blot.read(base_context, content_types)
blot.write(context, {
'pages': ListWriter(
'pages',
'essay.html',
'{dirname}/index.html'),
'posts': ListWriter(
'posts',
'posts/detail.html',
'posts/{category}/{slug}/{filename}.html'),
'post_index': PaginatedWriter(
'posts',
'posts/index.html',
'index{page}.html'),
'series': ListWriter(
'series',
'series/detail.html',
'series/{name}/index.html'),
'series_index': IndexWriter(
'series',
"series/index.html",
"series/index.html"),
'categories': ListWriter(
'categories',
'categories/detail.html',
'posts/{name}/index.html'),
'category_index': IndexWriter(
'categories',
"categories/index.html",
"posts/index.html"),
'tags': ListWriter(
'tags',
'tags/detail.html',
'tags/{name}/index.html'),
'tag_index': IndexWriter(
'tags',
"tags/index.html",
"tags/index.html"),
'pageimages': StaticWriter(
'pageimages',
"{parent}/{basename}"),
'postimages': StaticWriter(
'postimages',
"{parent}/{basename}"),
'staticfiles': StaticWriter(
'staticfiles',
"static/{dirname}/{basename}"),
'sass': StaticWriter(
'sass',
"static/site.css"),
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment