Skip to content

Commit 00a35c4

Browse files
committed
add(model): create MkdocsPageSubset to store Pages refs accross signals
1 parent 4f67a41 commit 00a35c4

File tree

1 file changed

+33
-1
lines changed

1 file changed

+33
-1
lines changed

mkdocs_rss_plugin/models.py

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,16 @@
44
# ########## Libraries #############
55
# ##################################
66

7+
78
# standard
9+
from collections.abc import MutableMapping
810
from dataclasses import dataclass, field
911
from datetime import datetime
1012
from pathlib import Path
11-
from typing import Optional
13+
from typing import Any, Optional
14+
15+
# 3rd party
16+
from mkdocs.structure.pages import Page
1217

1318
# package modules
1419
from mkdocs_rss_plugin.__about__ import __title__, __version__
@@ -18,6 +23,30 @@
1823
# ##################################
1924

2025

26+
@dataclass
27+
class MkdocsPageSubset:
28+
"""Minimal subset of a Mkdocs Page with only necessary attributes for plugin needs."""
29+
30+
dest_uri: str
31+
src_uri: str
32+
title: Optional[str] = None
33+
meta: Optional[MutableMapping[str, Any]] = None
34+
35+
@classmethod
36+
def from_page(cls, page: Page) -> "MkdocsPageSubset":
37+
"""Create a PageSubset from a Mkdocs page.
38+
39+
Args:
40+
page: MkDocs Page object
41+
"""
42+
return cls(
43+
meta=page.meta,
44+
title=page.title,
45+
src_uri=page.file.src_uri,
46+
dest_uri=page.file.dest_uri,
47+
)
48+
49+
2150
@dataclass
2251
class PageInformation:
2352
"""Object describing a page information gathered from Mkdocs and used as feed's item."""
@@ -33,6 +62,9 @@ class PageInformation:
3362
updated: Optional[datetime] = None
3463
url_comments: Optional[str] = None
3564
url_full: Optional[str] = None
65+
_mkdocs_page_ref: Optional[MkdocsPageSubset] = field(
66+
default=None, repr=False, compare=False
67+
)
3668

3769

3870
@dataclass

0 commit comments

Comments
 (0)