Cat Feeder  1.0.0
The Cat feeder project
Loading...
Searching...
No Matches
common_constants.py
Go to the documentation of this file.
1r"""
2# +==== BEGIN CatFeeder =================+
3# LOGO:
4# ..............(..../\
5# ...............)..(.')
6# ..............(../..)
7# ...............\‍(__)|
8# Inspired by Joan Stark
9# source https://www.asciiart.eu/
10# animals/cats
11# /STOP
12# PROJECT: CatFeeder
13# FILE: common_constants.py
14# CREATION DATE: 26-11-2025
15# LAST Modified: 14:43:52 19-12-2025
16# DESCRIPTION:
17# This is the backend server in charge of making the actual website work.
18# /STOP
19# COPYRIGHT: (c) Cat Feeder
20# PURPOSE: Common constants and utilities for all documentation providers.
21# // AR
22# +==== END CatFeeder =================+
23"""
24
25from typing import Optional
26
27# CDN base URLs (common across multiple providers)
28CDN_UNPKG_BASE: str = "https://unpkg.com"
29CDN_JSDELIVR_BASE: str = "https://cdn.jsdelivr.net"
30CDN_CDNJS_BASE: str = "https://cdnjs.cloudflare.com"
31
32# Common HTML document elements
33HTML_DOCTYPE: str = "<!DOCTYPE html>"
34HTML_META_CHARSET: str = '<meta charset="utf-8">'
35HTML_META_VIEWPORT: str = '<meta name="viewport" content="width=device-width, initial-scale=1">'
36
37
39 title: str,
40 body_content: str,
41 head_extra: str = "",
42 body_attributes: str = ""
43) -> str:
44 """Create a complete HTML page with common structure.
45
46 Args:
47 title (str): The page title.
48 body_content (str): The HTML content for the body.
49 head_extra (str, optional): Additional head elements. Defaults to "".
50 body_attributes (str, optional): Additional body tag attributes. Defaults to "".
51
52 Returns:
53 str: Complete HTML page as a string.
54 """
55 return f"""{HTML_DOCTYPE}
56<html lang="en">
57<head>
58 {HTML_META_CHARSET}
59 {HTML_META_VIEWPORT}
60 <title>{title}</title>
61 {head_extra}
62</head>
63<body{' ' + body_attributes if body_attributes else ''}>
64 {body_content}
65</body>
66</html>"""
67
68
69def create_cdn_script_tag(url: str, attributes: Optional[str] = None) -> str:
70 """Create a script tag for CDN resources.
71
72 Args:
73 url (str): The CDN URL for the script.
74 attributes (Optional[str], optional): Additional script attributes. Defaults to None.
75
76 Returns:
77 str: HTML script tag as a string.
78 """
79 attr_str = f" {attributes}" if attributes else ""
80 return f'<script src="{url}"{attr_str}></script>'
81
82
83def create_cdn_link_tag(url: str, rel: str = "stylesheet", attributes: Optional[str] = None) -> str:
84 """Create a link tag for CDN resources.
85
86 Args:
87 url (str): The CDN URL for the resource.
88 rel (str, optional): The rel attribute value. Defaults to "stylesheet".
89 attributes (Optional[str], optional): Additional link attributes. Defaults to None.
90
91 Returns:
92 str: HTML link tag as a string.
93 """
94 attr_str = f" {attributes}" if attributes else ""
95 return f'<link rel="{rel}" href="{url}"{attr_str}>'
str create_cdn_link_tag(str url, str rel="stylesheet", Optional[str] attributes=None)
str create_html_page(str title, str body_content, str head_extra="", str body_attributes="")
str create_cdn_script_tag(str url, Optional[str] attributes=None)