Skip to content

Commit

Permalink
imrpovements
Browse files Browse the repository at this point in the history
  • Loading branch information
sangam14 committed Dec 2, 2023
1 parent d1b7f8f commit 9e8e13e
Show file tree
Hide file tree
Showing 12 changed files with 128 additions and 46 deletions.
2 changes: 1 addition & 1 deletion assets/js/component/dropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ document.body.addEventListener('click', function (e) {
if (!isDropdownMenu) {
document.querySelectorAll(dropdownOpenSelector).forEach(el => el.classList.remove('show'));
}
});
});
2 changes: 1 addition & 1 deletion assets/js/component/toc.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ if ('IntersectionObserver' in window) {
}
});
});
}
}
42 changes: 21 additions & 21 deletions assets/scss/base.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,24 @@
* Licensed under the MIT License.
*/

@import "reset";
@import "variables";
@import "layout";

@import "component/site-header";
@import "component/site-footer";
@import "component/article";
@import "component/sidebar";
@import "component/toc";

@import "component/button";
@import "component/dropdown";
@import "component/chroma";

html {
font-family: var(--font-family);
background: var(--background);
color: var(--color);
scroll-behavior: smooth;
scroll-padding: 2em;
}
@import "reset";
@import "variables";
@import "layout";
@import "component/site-header";
@import "component/site-footer";
@import "component/article";
@import "component/sidebar";
@import "component/toc";
@import "component/button";
@import "component/dropdown";
@import "component/chroma";
html {
font-family: var(--font-family);
background: var(--background);
color: var(--color);
scroll-behavior: smooth;
scroll-padding: 2em;
}
2 changes: 1 addition & 1 deletion assets/scss/component/_button.scss
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@
border: 1px dotted var(--border-color);
border-radius: 4px;
cursor: pointer;
}
}
2 changes: 1 addition & 1 deletion assets/scss/component/sidebar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,4 @@

.sidebar-link.current::before, .sidebar-link:hover::before {
background: var(--color-anchor);
}
}
2 changes: 1 addition & 1 deletion data/en/containersecurity/sidebar.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
pages:
- title: Overview

- title: ContainerSecurity
- title: 🔒ContainerSecurity
pages:
- title: What is container?
- title: Container vs Virtualization
Expand Down
2 changes: 1 addition & 1 deletion data/en/docker/sidebar.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
pages:
- title: Overview

- title: Learn Docker
- title: 🐳 Learn Docker
pages:
- title: Pre-requisit for this lab
- title: Docker Hello World Example
Expand Down
2 changes: 1 addition & 1 deletion data/en/k8s/sidebar.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
pages:
- title: Overview

- title: kubernetes
- title: kubernetes
pages:
- title: Pre-requisit for this lab
- title: Basics of Pod
Expand Down
12 changes: 10 additions & 2 deletions layouts/partials/scripts.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{{ $dropdown := resources.Get "js/component/dropdown.js" }}
{{ $colorPreference := resources.Get "js/component/color-preference.js" }}
{{ $articleNav := resources.Get "js/component/article-nav.js" }}
{{ $sidebar := resources.Get "js/component/sidebar.js" }}
{{ $toc := resources.Get "js/component/toc.js" }}
{{ $baseJs := slice $dropdown $colorPreference $articleNav $toc | resources.Concat "js/base.js" | minify }}
{{ $baseJs := slice $dropdown $colorPreference $articleNav $sidebar $toc | resources.Concat "js/base.js" | minify }}

<script type="text/javascript" src="{{ $baseJs.RelPermalink }}"></script>

Expand All @@ -18,4 +19,11 @@
apiKey: '{{ $algolia.apiKey }}',
});
</script>
{{ end }}
{{ end }}

<script type="application/javascript">
if('serviceWorker' in navigator) {
navigator.serviceWorker.register('/sw.js?{{ now.Format "2006-01-02" }}')
.catch(function(err) {console.error('ServiceWorker registration failed: ', err);});
}
</script>
42 changes: 28 additions & 14 deletions layouts/partials/sidebar.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,37 @@

<aside id="sidebar">
<span class="btn-close"><i class="icon icon-close"></i></span>
{{- range $group := $data -}}
<strong class="sidebar-section">{{ $group.title }}</strong>

{{- range $page := $group.pages -}}
{{- $pageSlug := $page.title | urlize -}}
{{- $isActivePage := eq $urlPageSlug $pageSlug -}}
<div class="sticky">
{{- range $group := $data -}}
<strong class="sidebar-section">{{ $group.title }}</strong>

{{ if eq .Site.Language.Lang .Site.DefaultContentLanguage }}
{{ $href := printf "/%s/%s/" $.Section $pageSlug }}
<a class="sidebar-link {{ if $isActivePage }}current{{ end }}" href="{{ $href }}">{{ $page.title }}</a>
{{- range $index, $page := $group.pages -}}
{{- $pageSlug := $page.title | urlize -}}
{{- $isActivePage := eq $urlPageSlug $pageSlug -}}

{{ else }}
{{ $href := printf "/%s/%s/%s/" $.Site.Language.Lang $.Section $pageSlug }}
<a class="sidebar-link {{ if $isActivePage }}current{{ end }}" href="{{ $href }}">{{ $page.title }}</a>
{{ if eq .Site.Language.Lang .Site.DefaultContentLanguage }}
{{ $href := printf "/%s/%s/" $.Section $pageSlug }}
<a class="sidebar-link {{ if $isActivePage }}current{{ end }}" href="{{ $href }}">
{{ if and (eq $index 0) $group.replaceFirstPageTitle }}
{{ $group.replaceFirstPageTitle }}
{{ else }}
{{ $page.title }}
{{ end }}
</a>

{{ end}}
{{- end }}
{{ else }}
{{ $href := printf "/%s/%s/%s/" $.Site.Language.Lang $.Section $pageSlug }}
<a class="sidebar-link {{ if $isActivePage }}current{{ end }}" href="{{ $href }}">
{{ if and (eq $index 0) $group.replaceFirstPageTitle }}
{{ $group.replaceFirstPageTitle }}
{{ else }}
{{ $page.title }}
{{ end }}
</a>
{{ end}}
{{- end }}

{{- end }}
{{- end }}
</div>
</aside>
3 changes: 1 addition & 2 deletions layouts/partials/site-header.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<header id="site-header">
<!-- brand -->
<div id="site-header-brand">
<!-- <img src="/img/logos/KubeDaily-1.png" width="24" height="24"> -->
<!-- <a href="/">{{ .Site.Title }}</a> -->
<a href="/">{{ .Site.Title }}</a>
</div>

<!-- controls -->
Expand Down
61 changes: 61 additions & 0 deletions static/sw.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
const cacheName = 'docura-{{ now.Format "2006-01-02" }}';
const staticAssets = [
'./',
'./index.html',
'./manifest.json',
'./docs/**/*',
'./font/*',
'./img/icon/favicon.ico',
'./img/icon/icon-16.png',
'./img/icon/icon-32.png',
'./img/icon/icon-180.png',
'./img/icon/icon-192.png',
'./img/icon/icon-512.png',
'./img/icon/icon-vector.svg',
'./img/icon/maskable-icon-192.png',
'./img/icon/maskable-icon-512.png',
'./js/base.min.js',
'./js/component/docsearch.min.js',
'./scss/base.css',
'./scss/component/docsearch.css',
'./scss/home.css',
];

self.addEventListener('install', async e => {
const cache = await caches.open(cacheName);
await cache.addAll(staticAssets);
return self.skipWaiting();
});

self.addEventListener('activate', e => {
self.clients.claim();
});

self.addEventListener('fetch', async e => {
const req = e.request;
const url = new URL(req.url);

if (url.origin === location.origin) {
e.respondWith(cacheFirst(req));
} else {
e.respondWith(networkFirst(req));
}
});

async function cacheFirst(req) {
const cache = await caches.open(cacheName);
const cached = await cache.match(req);
return cached || fetch(req);
}

async function networkFirst(req) {
const cache = await caches.open(cacheName);
try {
const fresh = await fetch(req);
cache.put(req, fresh.clone());
return fresh;
} catch (e) {
const cached = await cache.match(req);
return cached;
}
}

0 comments on commit 9e8e13e

Please sign in to comment.