From 6e63cb31aa78b6d6cbf8eb9d0398e13d5e576d05 Mon Sep 17 00:00:00 2001 From: Ujjwal Baskota <19787410+ubaskota@users.noreply.github.com> Date: Wed, 4 Dec 2024 17:09:25 -0500 Subject: [PATCH 1/7] This change updates the furo generator files to remove inline styles and scripts to make them compatible with the new security headers --- docs/source/_static/css/custom.css | 4 + docs/source/_static/css/dark_light_mode.css | 20 ++++ docs/source/_static/js/loadShortbread.js | 27 +++++ .../_templates/_head_css_variables.html | 31 +++++ docs/source/_templates/base.html | 107 ++++++++++++++++++ docs/source/_templates/layout.html | 61 ++++++++++ docs/source/_templates/page.html | 24 ++-- 7 files changed, 259 insertions(+), 15 deletions(-) create mode 100644 docs/source/_static/css/dark_light_mode.css create mode 100644 docs/source/_static/js/loadShortbread.js create mode 100644 docs/source/_templates/_head_css_variables.html create mode 100644 docs/source/_templates/base.html create mode 100644 docs/source/_templates/layout.html diff --git a/docs/source/_static/css/custom.css b/docs/source/_static/css/custom.css index 5be72283d4..5789dfff8b 100644 --- a/docs/source/_static/css/custom.css +++ b/docs/source/_static/css/custom.css @@ -103,3 +103,7 @@ h3.admonition-title::before { mask-image: var(--icon-admonition-default); mask-repeat: no-repeat; } +/* Apply SVG from inline page.html */ +.hidden-svg { + display: none; +} diff --git a/docs/source/_static/css/dark_light_mode.css b/docs/source/_static/css/dark_light_mode.css new file mode 100644 index 0000000000..405fdb59a0 --- /dev/null +++ b/docs/source/_static/css/dark_light_mode.css @@ -0,0 +1,20 @@ +body { + --color-code-background: #f8f8f8; + --color-code-foreground: black; +} + +/* Dark theme styles */ +@media not print { + body[data-theme="dark"] { + --color-code-background: #272822; + --color-code-foreground: #f8f8f2; + } + + /* For users who prefer dark color scheme */ + @media (prefers-color-scheme: dark) { + body:not([data-theme="light"]) { + --color-code-background: #272822; + --color-code-foreground: #f8f8f2; + } + } +} diff --git a/docs/source/_static/js/loadShortbread.js b/docs/source/_static/js/loadShortbread.js new file mode 100644 index 0000000000..6b31b35f4a --- /dev/null +++ b/docs/source/_static/js/loadShortbread.js @@ -0,0 +1,27 @@ +// Load shortbread +document.addEventListener('DOMContentLoaded', function() { + + document.body.dataset.theme = localStorage.getItem("theme") || "auto"; + + if (typeof AWSCShortbread !== 'undefined') { + const shortbread = AWSCShortbread({ + // domain: ".amazonaws.com" + domain: "d3o2vvnrhogbwx.cloudfront.net" + }); + + // Check for cookie consent + shortbread.checkForCookieConsent(); + + // Add event listener for 'Cookie preferences' button read from page.html + const cookiePreferencesLink = document.getElementById('cookie-button-link'); + if (cookiePreferencesLink) { + cookiePreferencesLink.addEventListener('click', function(event) { + event.preventDefault(); + shortbread.customizeCookies(); + }); + } + console.log("AWSCShortbread loaded successfully loaded!!!") + } else { + console.error("AWSCShortbread failed to load!!!") + } +}); diff --git a/docs/source/_templates/_head_css_variables.html b/docs/source/_templates/_head_css_variables.html new file mode 100644 index 0000000000..8c635eb50b --- /dev/null +++ b/docs/source/_templates/_head_css_variables.html @@ -0,0 +1,31 @@ +{# + This is where user-provided CSS variables get converted into actual values. +#} +{% macro declare_css_variables(user_customisations, pygments_theme) -%} + + --color-code-background: {{ pygments_theme.background }}; + --color-code-foreground: {{ pygments_theme.foreground }}; + {% if user_customisations -%} + {% for name, value in user_customisations.items() -%} + --{{ name }}: {{ value }}; + {% endfor %} + {%- endif %} +{%- endmacro %} + + + + diff --git a/docs/source/_templates/base.html b/docs/source/_templates/base.html new file mode 100644 index 0000000000..580a01028c --- /dev/null +++ b/docs/source/_templates/base.html @@ -0,0 +1,107 @@ + + + + + + + {%- block site_meta -%} + + + + + {%- if metatags %}{{ metatags }}{% endif -%} + + {%- block linktags %} + {%- if hasdoc('about') -%} + + {%- endif -%} + {%- if hasdoc('genindex') -%} + + {%- endif -%} + {%- if hasdoc('search') -%} + + {%- endif -%} + {%- if hasdoc('copyright') -%} + + {%- endif -%} + {%- if next -%} + + {%- endif -%} + {%- if prev -%} + + {%- endif -%} + {#- rel="canonical" (set by html_baseurl) -#} + {%- if pageurl %} + + {%- endif %} + {%- endblock linktags %} + + {# Favicon #} + {%- if favicon_url -%} + + {%- endif -%} + + + + {%- endblock site_meta -%} + + {#- Site title -#} + {%- block htmltitle -%} + {% if not docstitle %} + {{ title|striptags|e }} + {% elif pagename == master_doc %} + {{ docstitle|striptags|e }} + {% else %} + {{ title|striptags|e }} - {{ docstitle|striptags|e }} + {% endif %} + {%- endblock -%} + + {%- block styles -%} + + {# Custom stylesheets #} + {%- block regular_styles -%} + {%- for css in css_files -%} + {% if css|attr("filename") -%} + {{ css_tag(css) }} + {%- else -%} + + {%- endif %} + {% endfor -%} + {%- endblock regular_styles -%} + + {#- Theme-related stylesheets -#} + {%- block theme_styles %} + {% include "_head_css_variables.html" with context %} + {%- endblock -%} + + {%- block extra_styles %} + {%- endblock -%} + + {%- endblock styles -%} + + {#- Custom front matter #} + {%- block extrahead -%}{%- endblock -%} + + + {% block body %} + + {% endblock %} + + {%- block scripts -%} + + {# Custom JS #} + {%- block regular_scripts -%} + {% for path in script_files -%} + {{ js_tag(path) }} + {% endfor -%} + {%- endblock regular_scripts -%} + + {# Theme-related JavaScript code #} + {%- block theme_scripts -%} + {%- endblock -%} + + {%- endblock scripts -%} + + \ No newline at end of file diff --git a/docs/source/_templates/layout.html b/docs/source/_templates/layout.html new file mode 100644 index 0000000000..7b04258902 --- /dev/null +++ b/docs/source/_templates/layout.html @@ -0,0 +1,61 @@ +{# Adapted from Just the Docs #} + + + Contents + + + + + + Menu + + + + + + + + Expand + + + + + + Light mode + + + + + + + + + + + + + + Dark mode + + + + + + + Auto light/dark mode + + + + + + + + + + + \ No newline at end of file diff --git a/docs/source/_templates/page.html b/docs/source/_templates/page.html index 68cc2615d4..0d3b712686 100644 --- a/docs/source/_templates/page.html +++ b/docs/source/_templates/page.html @@ -9,14 +9,12 @@ furnished to do so, subject to the following conditions: #} -{%- extends "!page.html" %} +{% extends "base.html" %} + {% block body -%} - -{% include "partials/icons.html" %} - +{% include 'layout.html' %} + Close Menu - - - Privacy | Site Terms | Cookie preferences + + + Privacy | + Site Terms | + Cookie preferences {# end of AWS modification of Furo template #} From f7082cc06e5b4c49e441b6fa3ece45620aaf8654 Mon Sep 17 00:00:00 2001 From: Ujjwal Baskota <19787410+ubaskota@users.noreply.github.com> Date: Thu, 5 Dec 2024 15:19:25 -0500 Subject: [PATCH 2/7] modifies a filename --- docs/source/_templates/base.html | 2 +- docs/source/_templates/head_css_variables.html | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 docs/source/_templates/head_css_variables.html diff --git a/docs/source/_templates/base.html b/docs/source/_templates/base.html index 580a01028c..d5476e8216 100644 --- a/docs/source/_templates/base.html +++ b/docs/source/_templates/base.html @@ -71,7 +71,7 @@ {#- Theme-related stylesheets -#} {%- block theme_styles %} - {% include "_head_css_variables.html" with context %} + {% include "head_css_variables.html" with context %} {%- endblock -%} {%- block extra_styles %} diff --git a/docs/source/_templates/head_css_variables.html b/docs/source/_templates/head_css_variables.html new file mode 100644 index 0000000000..9ff322f5f0 --- /dev/null +++ b/docs/source/_templates/head_css_variables.html @@ -0,0 +1,13 @@ +{# + This is where user-provided CSS variables get converted into actual values. +#} +{% macro declare_css_variables(user_customisations, pygments_theme) -%} + + --color-code-background: {{ pygments_theme.background }}; + --color-code-foreground: {{ pygments_theme.foreground }}; + {% if user_customisations -%} + {% for name, value in user_customisations.items() -%} + --{{ name }}: {{ value }}; + {% endfor %} + {%- endif %} +{%- endmacro %} From 07e3c33db33c25b158e3b84401de7b39323e0f1f Mon Sep 17 00:00:00 2001 From: Ujjwal Baskota <19787410+ubaskota@users.noreply.github.com> Date: Thu, 5 Dec 2024 15:48:12 -0500 Subject: [PATCH 3/7] edits some comments --- docs/source/_static/js/loadShortbread.js | 2 +- docs/source/_templates/page.html | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/docs/source/_static/js/loadShortbread.js b/docs/source/_static/js/loadShortbread.js index 6b31b35f4a..5b4da8cd0f 100644 --- a/docs/source/_static/js/loadShortbread.js +++ b/docs/source/_static/js/loadShortbread.js @@ -12,7 +12,7 @@ document.addEventListener('DOMContentLoaded', function() { // Check for cookie consent shortbread.checkForCookieConsent(); - // Add event listener for 'Cookie preferences' button read from page.html + // Add event listener for 'Cookie preferences' link read from page.html const cookiePreferencesLink = document.getElementById('cookie-button-link'); if (cookiePreferencesLink) { cookiePreferencesLink.addEventListener('click', function(event) { diff --git a/docs/source/_templates/page.html b/docs/source/_templates/page.html index 0d3b712686..a945f196c4 100644 --- a/docs/source/_templates/page.html +++ b/docs/source/_templates/page.html @@ -174,8 +174,6 @@ {%- endif %} {# start of AWS modification of Furo template #}