Skip to content

Commit

Permalink
refacto: move global variables to constants module and rename customt…
Browse files Browse the repository at this point in the history
…ypes into models (#210)
  • Loading branch information
Guts authored Dec 5, 2023
2 parents f16bd1f + e358298 commit db69324
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 20 deletions.
24 changes: 24 additions & 0 deletions mkdocs_rss_plugin/constants.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#! python3 # noqa: E265

# ############################################################################
# ########## Libraries #############
# ##################################

# standard library
from pathlib import Path

# package
from mkdocs_rss_plugin import __about__

# ############################################################################
# ########## Globals #############
# ################################

DEFAULT_TEMPLATE_FOLDER = Path(__file__).parent / "templates"
DEFAULT_TEMPLATE_FILENAME = DEFAULT_TEMPLATE_FOLDER / "rss.xml.jinja2"
OUTPUT_FEED_CREATED = "feed_rss_created.xml"
OUTPUT_FEED_UPDATED = "feed_rss_updated.xml"
REMOTE_REQUEST_HEADERS = {
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
"User-Agent": f"{__about__.__title__}/{__about__.__version__}",
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# ########## Libraries #############
# ##################################

# standard library
# standard
from datetime import datetime
from pathlib import Path
from typing import NamedTuple
Expand Down
27 changes: 14 additions & 13 deletions mkdocs_rss_plugin/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from email.utils import formatdate
from pathlib import Path
from re import compile
from typing import Optional

# 3rd party
from jinja2 import Environment, FileSystemLoader, select_autoescape
Expand All @@ -23,18 +24,18 @@
# package modules
from mkdocs_rss_plugin.__about__ import __title__, __uri__, __version__
from mkdocs_rss_plugin.config import RssPluginConfig
from mkdocs_rss_plugin.customtypes import PageInformation
from mkdocs_rss_plugin.constants import (
DEFAULT_TEMPLATE_FILENAME,
DEFAULT_TEMPLATE_FOLDER,
OUTPUT_FEED_CREATED,
OUTPUT_FEED_UPDATED,
)
from mkdocs_rss_plugin.models import PageInformation
from mkdocs_rss_plugin.util import Util

# ############################################################################
# ########## Globals #############
# ################################

DEFAULT_TEMPLATE_FOLDER = Path(__file__).parent / "templates"
DEFAULT_TEMPLATE_FILENAME = DEFAULT_TEMPLATE_FOLDER / "rss.xml.jinja2"
OUTPUT_FEED_CREATED = "feed_rss_created.xml"
OUTPUT_FEED_UPDATED = "feed_rss_updated.xml"

logger = logging.getLogger("mkdocs.mkdocs_rss_plugin")


Expand All @@ -50,14 +51,14 @@ def __init__(self):
"""Instanciation."""
# dates source
self.src_date_created = self.src_date_updated = "git"
self.meta_datetime_format = None
self.meta_default_timezone = "UTC"
self.meta_default_time = None
self.meta_datetime_format: Optional[str] = None
self.meta_default_timezone: str = "UTC"
self.meta_default_time: Optional[str] = None
# pages storage
self.pages_to_filter = []
self.pages_to_filter: list = []
# prepare output feeds
self.feed_created = dict
self.feed_updated = dict
self.feed_created: dict = {}
self.feed_updated: dict = {}

def on_config(self, config: config_options.Config) -> dict:
"""The config event is the first event called on build and
Expand Down
7 changes: 1 addition & 6 deletions mkdocs_rss_plugin/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from mkdocs.utils import get_build_datetime

# package
from mkdocs_rss_plugin import __about__
from mkdocs_rss_plugin.constants import REMOTE_REQUEST_HEADERS
from mkdocs_rss_plugin.git_manager.ci import CiHandler

# conditional imports
Expand All @@ -38,11 +38,6 @@
# ########## Globals #############
# ################################

REMOTE_REQUEST_HEADERS = {
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
"User-Agent": f"{__about__.__title__}/{__about__.__version__}",
}

logger = logging.getLogger("mkdocs.mkdocs_rss_plugin")


Expand Down

0 comments on commit db69324

Please sign in to comment.