models.Post - Post

class crotal.models.Post(**attributes)[source]

Model Post for posts in the blog.

Attributes:

PATH: A list of relative paths where this model is related to, please use the relative path to this script.

FILE_EXTENSIONS: A list containing file extensions. Only the files with these file extensions shall be read by the model.

title: Title of the post.

slug: Slug of the post that may be used in its url.

pub_date: Publication date of the post.

tags: A list of Tags that the post is related to.

categories: A list of Categories that the post belongs to.

raw_content: The raw markdown content of the post.

html_content: The html format post content generated from markdown file(raw_content).

short_html_content: A short version of the html_content, which may be represented on the index page.

create()[source]

This method:

  1. Converts the post content from markdown into html format.
  2. Extracts a list of image urls.
  3. Creates a short version of the post content for display.
  4. Converts the categories and tags from string to object.
Returns
classmethod load_extra_items(config)[source]

Load Archive, Categorie and Tag objects created from this Post into the object manger of their own class. :param config: :return:

generate_url(permalink)[source]

Save the post url by the permalink in config file.

The permalink is seperated into servel parts from '/'. If one part of it startswith ':', then we should find whether there is attribute with the same name in the post. If not, we take it as a string.

example: '/post/2013/11/hello-world/' can be generated from /post/:year/:month/:title

escape_keywords(word)[source]

This method serves like a switch statement, return field by the indicated keyword. :param word: year, month, day, title or category :return: The corresponding item as a string.