mkdocs_rss_plugin.util module

class mkdocs_rss_plugin.util.Util(path='.')[source]

Bases: object

build_url(base_url, path, args_dict=None)[source]

Build URL using base URL, cumulating existing and passed path, then adding URL arguments.

Parameters
  • base_url (str) – base URL with existing path to use

  • path (str) – URL path to cumulate with existing

  • args_dict (dict, optional) – URL arguments to add, defaults to None

Returns

complete and valid URL

Return type

str

static filter_pages(pages, attribute, length)[source]

Filter and return pages into a friendly RSS structure.

Parameters
  • pages (dict) – pages to filter

  • attribute (str) – page attribute as filter variable

  • length (int) – max number of pages to return

Returns

list of filtered pages

Return type

list

get_authors_from_meta(in_page)[source]

Returns authors from page meta. It handles ‘author’ and ‘authors’ for keys, str and iterable as values types.

Args:

in_page (Page): page to look at

Returns:

Tuple[str]: tuple of authors names

Return type

Tuple[str]

get_date_from_meta(date_metatag_value, meta_datetime_format)[source]

Get date from page.meta handling str with associated datetime format and date already transformed by MkDocs.

Parameters
  • date_metatag_value (str) – value of page.meta.{tag_for_date}

  • meta_datetime_format (str) – expected format of datetime

Returns

datetime as timestamp

Return type

float

get_description_or_abstract(in_page, chars_count=150)[source]

Returns description from page meta. If it doesn’t exist, use the {chars_count} first characters from page content (in markdown).

Parameters
  • in_page (Page) – [description]

  • chars_count (int) – [description]. Defaults to: 150 - optional

Returns

page description to use

Return type

str

get_file_dates(in_page, source_date_creation='git', source_date_update='git', meta_datetime_format='%Y-%m-%d %H:%M')[source]

Extract creation and update dates from page metadata (yaml frontmatter) or git log for given file.

Parameters
  • in_page (Page) – input page to work with

  • source_date_creation (str, optional) – which source to use (git or meta tag) for creation date, defaults to “git”

  • source_date_update (str, optional) – which source to use (git or meta tag) for update date, defaults to “git”

  • meta_datetime_format (str, optional) – datetime string format, defaults to “%Y-%m-%d %H:%M”

Returns

tuple of timestamps (creation date, last commit date)

Return type

Tuple[int, int]

get_image(in_page, base_url)[source]

Get image from page meta and returns properties.

Parameters
  • in_page (Page) – page to parse

  • base_url (str) – website URL to resolve absolute URLs for images referenced with local path.

Returns

(image url, mime type, image length)

Return type

tuple

get_local_image_length(page_path, path_to_append)[source]

Build URL using base URL, cumulating existing and passed path, then adding URL arguments.

Parameters
  • page_path (str) – base URL with existing path to use

  • path (str) – URL path to cumulate with existing

Returns

complete and valid path

Return type

str

get_remote_image_length(image_url, http_method='HEAD', attempt=0, ssl_context=None)[source]

Retrieve length for remote images (starting with ‘http’ in meta.image or meta.illustration). It tries to perform a HEAD request and get the length from the headers. If it fails, it tries again with a GET and disabling SSL verification.

Parameters
  • image_url (str) – remote image URL

  • http_method (str, optional) – HTTP method used to perform request, defaults to “HEAD”

  • attempt (int, optional) – request tries counter, defaults to 0

  • ssl_context (ssl.SSLContext, optional) – SSL context, defaults to None

Returns

image length

Return type

int

static get_site_url(mkdocs_config)[source]

Extract site URL from MkDocs configuration and enforce the behavior to ensure returning a str with length > 0 or None. If exists, it adds an ending slash.

Parameters

mkdocs_config (Config) – configuration object

Returns

site url

Return type

str or None

static guess_locale(mkdocs_config)[source]

Extract language code from MkDocs or Theme configuration.

Parameters

mkdocs_config (Config) – configuration object

Returns

language code

Return type

str or None