-
-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathmodels.py
More file actions
98 lines (80 loc) · 2.71 KB
/
models.py
File metadata and controls
98 lines (80 loc) · 2.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#! python3 # noqa: E265
# ############################################################################
# ########## Libraries #############
# ##################################
# for class autoref typing
from __future__ import annotations
# standard
from dataclasses import dataclass, field
from typing import TYPE_CHECKING, Any
# package modules
from mkdocs_rss_plugin.__about__ import __title__, __version__
if TYPE_CHECKING:
from collections.abc import MutableMapping
from datetime import datetime
from pathlib import Path
from mkdocs.structure.pages import Page
# ############################################################################
# ########## Classes ###############
# ##################################
@dataclass
class MkdocsPageSubset:
"""Minimal subset of a Mkdocs Page with only necessary attributes for plugin needs."""
abs_src_path: str
dest_uri: str
src_uri: str
title: str | None = None
meta: MutableMapping[str, Any] | None = None
@classmethod
def from_page(cls, page: Page) -> MkdocsPageSubset:
"""Create a PageSubset from a Mkdocs page.
Args:
page: MkDocs Page object
"""
return cls(
abs_src_path=page.file.abs_src_path,
meta=page.meta,
title=page.title,
src_uri=page.file.src_uri,
dest_uri=page.file.dest_uri,
)
@dataclass
class PageInformation:
"""Object describing a page information gathered from Mkdocs and used as feed's item."""
abs_path: Path | None = None
categories: list | None = None
authors: tuple | None = None
comments_url: str | None = None
created: datetime | None = None
description: str | None = None
guid: str | None = None
html_content: str | None = None
image: tuple[str, str, int] | None = None
link: str | None = None
pub_date: str | None = None
title: str | None = None
updated: datetime | None = None
# private
_mkdocs_page_ref: MkdocsPageSubset | None = field(
default=None, repr=False, compare=False
)
@dataclass
class RssFeedBase:
"""Object describing a feed."""
atom_url: str | None = None
author: str | None = None
buildDate: str | None = None
copyright: str | None = None
description: str | None = None
entries: list[PageInformation] = field(default_factory=list)
generator: str = f"{__title__} - v{__version__}"
html_url: str | None = None
json_url: str | None = None
language: str | None = None
logo_url: str | None = None
pubDate: str | None = None
repo_url: str | None = None
rss_url: str | None = None
stylesheet: str | None = None
title: str | None = None
ttl: int | None = None