Merge pull request #439 from nunocoracao/feature-412-sparkles-page-indicator-in-navigation-bar

 Page indicator in navigation bar
This commit is contained in:
Nuno Coração 2023-01-14 23:51:12 +00:00 committed by GitHub
commit 76a735e662
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 88 additions and 35 deletions

View file

@ -1177,15 +1177,20 @@ select {
.prose :where(a.active):not(:where([class~="not-prose"] *)) { .prose :where(a.active):not(:where([class~="not-prose"] *)) {
text-decoration-color: rgba(var(--color-primary-600), 1); text-decoration-color: rgba(var(--color-primary-600), 1);
text-decoration-line: underline; }
text-decoration-thickness: 3px;
text-underline-offset: 4px; .prose :where(p.active):not(:where([class~="not-prose"] *)) {
text-decoration-color: rgba(var(--color-primary-600), 1);
} }
.prose-invert :where(a.active):not(:where([class~="not-prose"] *)) { .prose-invert :where(a.active):not(:where([class~="not-prose"] *)) {
text-decoration-color: rgba(var(--color-primary-400), 1); text-decoration-color: rgba(var(--color-primary-400), 1);
} }
.prose-invert :where(p.active):not(:where([class~="not-prose"] *)) {
text-decoration-color: rgba(var(--color-primary-400), 1);
}
.sr-only { .sr-only {
position: absolute; position: absolute;
width: 1px; width: 1px;
@ -3091,6 +3096,12 @@ body:has(#menu-controller:checked) {
z-index: 1000; z-index: 1000;
} }
.active {
text-decoration-line: underline;
text-decoration-thickness: 3px;
text-underline-offset: 4px;
}
.first\:mt-8:first-child { .first\:mt-8:first-child {
margin-top: 2rem; margin-top: 2rem;
} }
@ -3437,6 +3448,10 @@ body:has(#menu-controller:checked) {
text-decoration-color: rgba(var(--color-primary-400), 1); text-decoration-color: rgba(var(--color-primary-400), 1);
} }
.dark .dark\:prose-invert :where(p.active):not(:where([class~="not-prose"] *)) {
text-decoration-color: rgba(var(--color-primary-400), 1);
}
.dark .dark\:text-neutral-500 { .dark .dark\:text-neutral-500 {
--tw-text-opacity: 1; --tw-text-opacity: 1;
color: rgba(var(--color-neutral-500), var(--tw-text-opacity)); color: rgba(var(--color-neutral-500), var(--tw-text-opacity));

View file

@ -441,3 +441,9 @@ body:has(#menu-controller:checked) {
transition: visibility 0.3s, opacity 0.3s ease-in-out ; transition: visibility 0.3s, opacity 0.3s ease-in-out ;
z-index: 1000; z-index: 1000;
} }
.active {
text-decoration-line: underline;
text-decoration-thickness: 3px;
text-underline-offset: 4px;
}

View file

@ -1 +0,0 @@
//for future

View file

@ -19,6 +19,10 @@ enableCodeCopy = true
# defaultBackgroundImage = "IMAGE.jpg" # used as default for background images # defaultBackgroundImage = "IMAGE.jpg" # used as default for background images
# highlightCurrentMenuArea = true
# smartTOC = true
# smartTOCHideUnfocusedChildren = true
[header] [header]
layout = "basic" # valid options: basic, fixed layout = "basic" # valid options: basic, fixed

View file

@ -19,6 +19,10 @@ disableImageOptimization = true
defaultBackgroundImage = "/img/iceland.jpg" defaultBackgroundImage = "/img/iceland.jpg"
highlightCurrentMenuArea = true
smartTOC = true
smartTOCHideUnfocusedChildren = false
[header] [header]
layout = "fixed" # valid options: basic, fixed layout = "fixed" # valid options: basic, fixed

View file

@ -129,7 +129,7 @@ Many of the article defaults here can be overridden on a per article basis by sp
### Global ### Global
| Name | Default | Description | | Name | Default | Description |
| -------------------------- | ------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | ------------------------------- | ------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `colorScheme` | `"blowfish"` | The theme colour scheme to use. Valid values are `blowfish` (default), `avocado`, `ocean`, `fire` and `slate`. Refer to the [Colour Schemes]({{< ref "getting-started#colour-schemes" >}}) section for more details. | | `colorScheme` | `"blowfish"` | The theme colour scheme to use. Valid values are `blowfish` (default), `avocado`, `ocean`, `fire` and `slate`. Refer to the [Colour Schemes]({{< ref "getting-started#colour-schemes" >}}) section for more details. |
| `defaultAppearance` | `"light"` | The default theme appearance, either `light` or `dark`. | | `defaultAppearance` | `"light"` | The default theme appearance, either `light` or `dark`. |
| `autoSwitchAppearance` | `true` | Whether the theme appearance automatically switches based upon the visitor's operating system preference. Set to `false` to force the site to always use the `defaultAppearance`. | | `autoSwitchAppearance` | `true` | Whether the theme appearance automatically switches based upon the visitor's operating system preference. Set to `false` to force the site to always use the `defaultAppearance`. |
@ -143,6 +143,9 @@ Many of the article defaults here can be overridden on a per article basis by sp
| `disableImageZoom` | `false` | Disables image zoom feature across all the images in the site. | | `disableImageZoom` | `false` | Disables image zoom feature across all the images in the site. |
| `disableImageOptimization` | `false` | Disables image resize and optimization features across all the images in the site. | | `disableImageOptimization` | `false` | Disables image resize and optimization features across all the images in the site. |
| `defaultBackgroundImage` | _Not set_ | Default background image for both `background` homepage layout and `background` hero style | | `defaultBackgroundImage` | _Not set_ | Default background image for both `background` homepage layout and `background` hero style |
| `defaultBackgroundImage` | _Not set_ | Marks menu entries in the main manu when selected |
| `smartTOC` | _Not set_ | Activate smart Table of Contents, items in view will be highlighted. |
| `smartTOCHideUnfocusedChildren` | _Not set_ | When smart Table of Contents is turned on, this will hide deeper levels of the table when they are not in focus. |
### Header ### Header

View file

@ -49,9 +49,6 @@
"sha512" }} "sha512" }}
<link type="text/css" rel="stylesheet" href="{{ $bundleCSS.RelPermalink }}" <link type="text/css" rel="stylesheet" href="{{ $bundleCSS.RelPermalink }}"
integrity="{{ $bundleCSS.Data.Integrity }}" /> integrity="{{ $bundleCSS.Data.Integrity }}" />
{{ $jsMain := resources.Get "js/main.js" }}
{{ $jsMain = $jsMain | resources.Minify | resources.Fingerprint "sha512" }}
<script type="text/javascript" src="{{ $jsMain.RelPermalink }}" integrity="{{ $jsMain.Data.Integrity }}"></script>
{{ $jsAppearance := resources.Get "js/appearance.js" }} {{ $jsAppearance := resources.Get "js/appearance.js" }}
{{ $jsAppearance = $jsAppearance | resources.Minify | resources.Fingerprint "sha512" }} {{ $jsAppearance = $jsAppearance | resources.Minify | resources.Fingerprint "sha512" }}
<script type="text/javascript" src="{{ $jsAppearance.RelPermalink }}" <script type="text/javascript" src="{{ $jsAppearance.RelPermalink }}"

View file

@ -1,5 +1,5 @@
<div style="padding-left:0;padding-right:0;padding-top:2px;padding-bottom:3px" <div style="padding-left:0;padding-right:0;padding-top:2px;padding-bottom:3px"
class="flex items-center justify-between px-4 py-6 sm:px-6 md:justify-start space-x-3"> class="main-menu flex items-center justify-between px-4 py-6 sm:px-6 md:justify-start space-x-3">
{{ if .Site.Params.Logo }} {{ if .Site.Params.Logo }}
{{ $logo := resources.Get .Site.Params.Logo }} {{ $logo := resources.Get .Site.Params.Logo }}
{{ if $logo }} {{ if $logo }}
@ -144,7 +144,8 @@
</div> </div>
{{ if .Site.Menus.subnavigation }} {{ if .Site.Menus.subnavigation }}
<div class="flex pb-3 flex-col items-end justify-between md:justify-start space-x-3" {{ if .Site.Params.Logo }} style="margin-top:-15px" {{ end }}> <div class="main-menu flex pb-3 flex-col items-end justify-between md:justify-start space-x-3" {{ if .Site.Params.Logo
}} style="margin-top:-15px" {{ end }}>
<div class="hidden md:flex items-center space-x-5"> <div class="hidden md:flex items-center space-x-5">
{{ range .Site.Menus.subnavigation }} {{ range .Site.Menus.subnavigation }}
<a href="{{ .URL }}" {{ if or (strings.HasPrefix .URL "http:" ) (strings.HasPrefix .URL "https:" ) }} <a href="{{ .URL }}" {{ if or (strings.HasPrefix .URL "http:" ) (strings.HasPrefix .URL "https:" ) }}
@ -162,3 +163,16 @@
</div> </div>
</div> </div>
{{ end }} {{ end }}
{{ if .Site.Params.highlightCurrentMenuArea }}
<script>
(function () {
var $mainmenu = $('.main-menu');
var path = window.location.pathname;
$mainmenu.find('a[href="' + path + '"]').each(function (i, e) {
console.log($(e).children('a'))
$(e).children('p').addClass('active');
});
})();
</script>
{{ end }}

View file

@ -18,8 +18,9 @@
{{ .TableOfContents | emojify }} {{ .TableOfContents | emojify }}
</div> </div>
</details> </details>
<script>
{{ if .Site.Params.smartTOC }}
<script>
(function () { (function () {
var $toc = $('#TableOfContents'); var $toc = $('#TableOfContents');
if ($toc.length > 0) { if ($toc.length > 0) {
@ -31,27 +32,34 @@
var id = ""; var id = "";
h.each(function (i, e) { h.each(function (i, e) {
e = $(e); e = $(e);
if (e.offset().top - $(window).height()/2 <= currentScroll) { if (e.offset().top - $(window).height()/3 <= currentScroll) {
id = e.attr('id'); id = e.attr('id');
} }
}); });
var active = $toc.find('a.active'); var active = $toc.find('a.active');
if (active.length == 1 && active.eq(0).attr('href') == '#' + id) return true; if (active.length == 1 && active.eq(0).attr('href') == '#' + id) return true;
active.each(function (i, e) { active.each(function (i, e) {
{{ if .Site.Params.smartTOCHideUnfocusedChildren }}
$(e).removeClass('active').siblings('ul').hide(); $(e).removeClass('active').siblings('ul').hide();
{{ else }}
$(e).removeClass('active');
{{ end }}
}); });
$toc.find('a[href="#' + id + '"]').addClass('active')
$toc.find('a[href="#' + id + '"]').parentsUntil('#TableOfContents').each(function (i, e) { $toc.find('a[href="#' + id + '"]').parentsUntil('#TableOfContents').each(function (i, e) {
console.log($(e).children('a')) $(e).children('a').parents('ul').show();
$(e).children('a').addClass('active').parents('ul').show();
}); });
} }
$window.on('scroll', onScroll); $window.on('scroll', onScroll);
$(document).ready(function () { $(document).ready(function () {
{{ if .Site.Params.smartTOCHideUnfocusedChildren }}
$toc.find('a').parent('li').find('ul').hide(); $toc.find('a').parent('li').find('ul').hide();
{{ end }}
onScroll(); onScroll();
}); });
} }
})(); })();
</script> </script>
{{ end }}

View file

@ -138,9 +138,9 @@ module.exports = {
}, },
'a.active': { 'a.active': {
"text-decoration-color": theme("colors.primary.600 / 1"), "text-decoration-color": theme("colors.primary.600 / 1"),
"text-decoration-line": "underline", },
"text-decoration-thickness": "3px", 'p.active': {
"text-underline-offset": "4px" "text-decoration-color": theme("colors.primary.600 / 1"),
} }
}, },
}, },
@ -161,6 +161,9 @@ module.exports = {
}, },
'a.active': { 'a.active': {
"text-decoration-color": theme("colors.primary.400 / 1") "text-decoration-color": theme("colors.primary.400 / 1")
},
'p.active': {
"text-decoration-color": theme("colors.primary.400 / 1")
} }
}, },
}, },