Skip to content

MF: Use css for data-mf instead of js #258

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion assets/css/docs-nginx-com/style.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
/*copy from nginx-theme.css */

[data-mf="false"] {
display: revert;
}

[data-mf="true"] {
display: none;
}

big,
html,
small {
Expand Down Expand Up @@ -2248,4 +2256,3 @@ text-decoration: none;
}

/*======END GDPR2==================*/

8 changes: 8 additions & 0 deletions assets/css/v2/style.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
[data-mf="true"] {
display: revert;
}

[data-mf="false"] {
display: none;
}

/* Regular */
@font-face {
font-family: "JetBrainsMono";
Expand Down
6 changes: 3 additions & 3 deletions layouts/_default/_markup/render-codeblock.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{{ $isSingleLine := eq (len $lines) 1 }}

{{- if $isSingleLine -}}
<div class="code-block" data-mf="true" style="display: none;">
<div class="code-block" data-mf="true">
<div class="code-container chroma">
<button onclick="copyToClipBoard(this, {{ $codeBlockId }})" class="code-copy-button" type="button">Copy</button>
<div class="highlight-v2 single-line" id="{{ $codeBlockId }}">
Expand All @@ -13,7 +13,7 @@
</div>
</div>
{{- else -}}
<div class="code-block" data-mf="true" style="display: none;">
<div class="code-block" data-mf="true">
{{- if and (ne .Type "") (ne .Type "none") -}}
<span class="code-type chroma">{{ .Type }}</span>
{{- end -}}
Expand All @@ -27,4 +27,4 @@
{{- end -}}
<div id="code-block-v1" data-mf="false">
{{ $result.Wrapped }}
</div>
</div>
80 changes: 24 additions & 56 deletions layouts/_default/baseof.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!DOCTYPE html>
<html lang="{{ .Site.LanguageCode }}">

<head>
<head>
<style>
body {
/* Hide entire body for first paint. This suppresses flicker when theme is loading. */
Expand All @@ -11,7 +11,7 @@
flex-direction: column;
}
</style>

<noscript>
<style>
/* Styles when JavaScript is disabled. Fallsback to old theme. */
Expand All @@ -20,7 +20,7 @@
}
</style>
</noscript>



<script>
Expand Down Expand Up @@ -56,43 +56,11 @@
}
});

// swap out v1 and v2 elements
const v1ElementIds = ["sidebar", "footer", "toc", "api", "search-v1", "breadcrumb-v1", "list-v1"]

v1ElementIds.forEach((elementId) => {
const element = document.getElementById(elementId);
if (element !== null) {
element.style.display = isNewTheme ? "none" : "";
}

const trustarc = document.getElementById("teconsent-v1");
const trustarc = document.getElementById("teconsent-v1");
if (trustarc) {
trustarc.id = isNewTheme ? "teconsent-v1" : "teconsent";
}
});

document.querySelectorAll(".table-v1").forEach((table) => {
table.style.display = isNewTheme ? "none" : "";
});

const notMfElements = ['[data-mf="false"]'];
notMfElements.forEach((elementId) => {
document.querySelectorAll(elementId).forEach((element) => {
element.style.display = isNewTheme ? "none" : "";
});
})

const mfElements = ['[data-mf="true"]'];
mfElements.forEach((elementId) => {
document.querySelectorAll(elementId).forEach((element) => {
element.style.display = isNewTheme ? "" : "none";

const trustarc = document.getElementById("teconsent-v2");
if (trustarc) {
trustarc.id = isNewTheme ? "teconsent" : "teconsent-v2";
}
});
});

document.getElementById("body").style.visibility = "visible";
};
Expand Down Expand Up @@ -131,72 +99,72 @@
{{ block "head" . }}

{{ partial "meta.html" . }}

{{ partial "favicon.html" . }}

{{ partial "styles.html" . }}

{{ if in .Params.doctypes "devportal" }}
{{ partial "devportal/style.html" . }}
{{ end }}

{{ if fileExists "/layouts/partials/head_custom.html" }}
{{ partial "head_custom.html" . }}
{{ end }}

{{ if or ( not hugo.IsServer ) ( not ( in .Site.Params.buildtype "package" ) ) }}

{{ partial "trustarc.html" . }}

{{ partial "tealium-profile.html" . }}

{{ end }}

{{ end }}

<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-K5HG9JT');</script>

</head>

<body id="body">
{{ if or ( not hugo.IsServer ) ( not ( in .Site.Params.buildtype "package" ) ) }}
{{ partial "universal-tag.html" . }}
{{ end }}

<header>
{{ block "header" . }}{{end}}
</header>

<section class="base-layout" data-testid="base-layout">
<section id="breadcrumb-v1">
<section id="breadcrumb-v1" data-mf="false">
{{ if not .IsHome }}
{{ if not (in .Params.display_breadcrumb "false" ) }}
{{ partial "breadcrumb" .}}
{{ partial "breadcrumb" .}}
{{ end }}
{{ end }}
</section>

<div class="main container-fluid min-page-height" data-menu-id="{{.RelPermalink}}">
{{ block "main" . }}{{ end }}
</div>
</section>

<footer id="footer">
<footer id="footer" data-mf="false">
{{ block "footer" . }}
{{ partial "footer.html" . }}
{{ end }}
</footer>

<footer data-mf="true" id="footer-v2" style="display:none;">
<footer data-mf="true" id="footer-v2">
{{ block "footer-v2" . }}
{{ partial "footer-v2.html" . }}
{{ end }}
</footer>
{{ partial "scripts.html" . }}
{{ partial "scripts.html" . }}
<div id="consent_blackbar"></div>
</body>
</html>
16 changes: 8 additions & 8 deletions layouts/_default/docs.html
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
{{ define "main" }}
<div class="docs-container row override-sidebar-collapse">
<div class="docs-container row override-sidebar-collapse">
<nav id="sidebar" class="sidenav overflow-auto col-md-3 d-none d-xl-block d-print-none align-top">
<nav data-mf="false" id="sidebar" class="sidenav overflow-auto col-md-3 d-none d-xl-block d-print-none align-top">
{{ partial "sidebar.html" . }}
</nav>

<!-- Replace icons -->
{{ $content := partial "icon-replacement.html" (dict "content" .Content) }}

{{if (.Params.catalog) }}
<main class="content content-has-toc" role="main">
{{ else if and (gt .WordCount 200 ) (.Params.toc) }}
<main class="content col d-block align-top content-has-toc" role="main">
{{ else }}
<main class="content col d-block align-top content-no-toc" role="main">
{{ end }}

<section class="main-layout">
<div class="sidebar-layout" id="sidebar-layout">
<button class="sidebar__mobile__toggle" aria-expanded="false" data-mf="true">{{ partial "lucide" (dict "context" . "icon" "x")}}Close</button>
Expand All @@ -26,10 +26,10 @@

<section id="maincontent" class="content-layout">
<div data-cms-edit="content" class="text-content">
<section class="breadcrumb-layout wide" data-mf="true" style="display: none;">
<section class="breadcrumb-layout wide" data-mf="true">
{{ if not .IsHome }}
{{ if not (in .Params.display_breadcrumb "false" ) }}
{{ partial "breadcrumb" .}}
{{ partial "breadcrumb" .}}
{{ end }}
{{ end }}
</section>
Expand All @@ -39,7 +39,7 @@ <h1>{{ .Title }}</h1>
{{ if in .Params.doctypes "beta" }}{{ partial "beta-badge" . }}{{ end }}

<hr>

{{ if .Page.Lastmod }}
<div class="last-modified">
{{ partial "page-meta-links" . }}
Expand All @@ -53,12 +53,12 @@ <h1>{{ .Title }}</h1>
</main>
{{ if and (gt .WordCount 200 ) (.Params.toc) }}
{{ if (add (len (findRE "<h3" .Content)) (len (findRE "<h2" .Content))) }}
<div id="toc" class="col-md-3 d-none d-xl-block d-print-none nginx-toc align-top">
<div data-mf="false" id="toc" class="col-md-3 d-none d-xl-block d-print-none nginx-toc align-top">
{{ partial "toc.html" . }}
</div>
{{ end }}
{{ end }}

</div>
</section>
</section>
Expand Down
15 changes: 9 additions & 6 deletions layouts/_default/list.html
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
{{ define "main" }}
<div data-mf="false">
<div class="row flex-xl-nowrap" id="list-v1">
<nav class="sidenav overflow-auto col-md-3 d-none d-xl-block d-print-none">
{{ partial "sidebar.html" . }}
</nav>
<main class="content col-xl-9 d-block" role="main">
{{ partial "list-main" . }}
{{ partial "list-main" . }}
</main>
</div>
</div>

{{/* mf list page */}}

<main class="content col d-block align-top content-has-toc" role="main" data-mf="true" style="display: none">
<div data-mf="true">
<main class="content col d-block align-top content-has-toc" role="main">
<section class="main-layout">
<div class="sidebar-layout" id="sidebar-layout">
<button class="sidebar__mobile__toggle" aria-expanded="false" data-mf="true">{{ partial "lucide" (dict "context" . "icon" "x")}}Close</button>
<nav data-mf="true" id="sidebar-v2" class="sidebar" style="display:none;">
<button class="sidebar__mobile__toggle" aria-expanded="false">{{ partial "lucide" (dict "context" . "icon" "x")}}Close</button>
<nav id="sidebar-v2" class="sidebar">
{{ partial "sidebar-v2.html" . }}
</nav>
</div>

<section id="maincontent" class="content-layout" data-mf="true" style="display: none">
<section id="maincontent" class="content-layout">
<div data-cms-edit="content" class="text-content list-page">
<section class="breadcrumb-layout wide">
{{ if not .IsHome }}
Expand Down Expand Up @@ -56,5 +59,5 @@ <h2>

</section>
</main>
</div>
{{ end }}

4 changes: 2 additions & 2 deletions layouts/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
{{ partial "sidebar.html" . }}
</nav>
<main class="content col-xl-9 d-block" role="main">
{{ partial "list-main" . }}
{{ partial "list-main" . }}
</main>
</div>
{{ end }}
{{ end }}
3 changes: 1 addition & 2 deletions layouts/partials/api.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<!--Use wide page layout for the API reference pages-->
<div class="nginx-docs-api-container">
<div class="nginx-docs-api-container">
<div id="api-component" class="content">
{{ .Content}}
</div>
</div>

4 changes: 2 additions & 2 deletions layouts/partials/callout.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
{{ if $isSpecialTitle }}
{{/* Loud callouts */}}
<div>
<blockquote class="{{ $class }}" data-mf="true" style="display: none;">
<blockquote class="{{ $class }}" data-mf="true">
<div>
<div class="call-out-type">
{{ partial "feather" (dict "context" . "icon" $icon) .}}
Expand All @@ -66,7 +66,7 @@

{{ $cleanTitle := strings.TrimSuffix ":" $title}}

<blockquote class="{{ $class }} note" data-mf="true" style="display: none;" data-title="{{ $cleanTitle }}">
<blockquote class="{{ $class }} note" data-mf="true" data-title="{{ $cleanTitle }}">
<div class="callout-content">
{{- with $icon -}}
<i class="{{ . }}"></i>
Expand Down
6 changes: 3 additions & 3 deletions layouts/partials/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<!--div class="CoveoAnalytics" data-search-hub="HUB_ES_Nginx_Docs_And_Org"></div-->
<div class="CoveoSearchbox" data-placeholder='Search NGINX Docs...'></div>
</div>
<atomic-search-interface id="search-standalone-header" data-mf="true" style="display:none;">
<atomic-search-interface id="search-standalone-header" data-mf="true">
<atomic-search-box redirection-url="/search.html">
</atomic-search-box>
</atomic-search-interface>
Expand All @@ -29,8 +29,8 @@
</ul>
</div>
{{ end }}
{{ $f5Sites := slice

{{ $f5Sites := slice
(dict "title" "DevCentral" "url" "https://community.f5.com/" "description" "Connect & learn in our hosted community")
(dict "title" "MyF5" "url" "https://my.f5.com/" "description" "Your key to everything F5, including support, registration keys, and subscriptions")
(dict "title" "NGINX" "url" "https://nginx.org/" "description" "Learn more about NGINX Open Source and read the community blog")
Expand Down
4 changes: 2 additions & 2 deletions layouts/partials/lucide.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{{- /* Usage: */ -}}
{{- /* (dict "context" . "icon" "circle") */ -}}
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" aria-hidden="true" class="lucide"
style="{{ .style | safeCSS }}" data-mf="true" style="display: none">
style="{{ .style | safeCSS }}" data-mf="true">
<use href="/images/lucide-sprite.svg#{{ .icon }}"></use>
</svg>
</svg>
Loading
Loading