fix: remove extra space for rendered link

chore: update theme info

chore: use dataset

chore: support editURL config option

* add toc and search config option

chore: update head template
This commit is contained in:
Xin 2023-08-12 19:53:14 +01:00
parent 03ae8b3dd5
commit d66ae7146f
8 changed files with 44 additions and 23 deletions

View File

@ -79,7 +79,7 @@
const result = resultsElement.querySelector('.active'); const result = resultsElement.querySelector('.active');
if (!result) return { result: undefined, index: -1 }; if (!result) return { result: undefined, index: -1 };
const index = parseInt(result.getAttribute('data-index')); const index = parseInt(result.dataset.index, 10);
return { result, index }; return { result, index };
} }
@ -101,7 +101,7 @@
function getResultsLength() { function getResultsLength() {
const { resultsElement } = getActiveSearchElement(); const { resultsElement } = getActiveSearchElement();
if (!resultsElement) return 0; if (!resultsElement) return 0;
return resultsElement.querySelectorAll('li').length; return resultsElement.dataset.count;
} }
// Finish the search by hiding the results and clearing the input. // Finish the search by hiding the results and clearing the input.
@ -304,6 +304,7 @@
return; return;
} }
// Highlight the query in the result text.
function highlightMatches(text, query) { function highlightMatches(text, query) {
const escapedQuery = query.replace(/[-\\^$*+?.()|[\]{}]/g, '\\$&'); const escapedQuery = query.replace(/[-\\^$*+?.()|[\]{}]/g, '\\$&');
const regex = new RegExp(escapedQuery, 'gi'); const regex = new RegExp(escapedQuery, 'gi');
@ -349,5 +350,6 @@
fragment.appendChild(li); fragment.appendChild(li);
} }
resultsElement.appendChild(fragment); resultsElement.appendChild(fragment);
resultsElement.dataset.count = results.length;
} }
})(); })();

View File

@ -2,19 +2,19 @@ document.querySelectorAll('.tabs-toggle').forEach(function (button) {
button.addEventListener('click', function (e) { button.addEventListener('click', function (e) {
// set parent tabs to unselected // set parent tabs to unselected
const tabs = Array.from(e.target.parentElement.querySelectorAll('.tabs-toggle')); const tabs = Array.from(e.target.parentElement.querySelectorAll('.tabs-toggle'));
tabs.map(tab => tab.setAttribute('data-state', '')); tabs.map(tab => tab.dataset.state = '');
// set current tab to selected // set current tab to selected
e.target.setAttribute('data-state', 'selected'); e.target.dataset.state = 'selected';
// set all panels to unselected // set all panels to unselected
const panelsContainer = e.target.parentElement.nextElementSibling; const panelsContainer = e.target.parentElement.nextElementSibling;
Array.from(panelsContainer.children).forEach(function (panel) { Array.from(panelsContainer.children).forEach(function (panel) {
panel.setAttribute('data-state', ''); panel.dataset.state = '';
}); });
const panelId = e.target.getAttribute('aria-controls'); const panelId = e.target.getAttribute('aria-controls');
const panel = panelsContainer.querySelector(`#${panelId}`); const panel = panelsContainer.querySelector(`#${panelId}`);
panel.setAttribute('data-state', 'selected'); panel.dataset.state = 'selected';
}); });
}); });

View File

@ -72,3 +72,13 @@ menu:
params: params:
displayUpdatedDate: true displayUpdatedDate: true
dateFormat: "January 2, 2006" dateFormat: "January 2, 2006"
toc:
disabled: false
search:
disabled: false
editURL:
disabled: false
base: "https://github.com/imfing/hextra/edit/dev/exampleSite/content"

View File

@ -1,2 +1,3 @@
article: article:
on_this_page: "On this page" on_this_page: "On this page"
edit_this_page: "Edit this page on GitHub →"

View File

@ -1 +1,3 @@
<a href="{{ .Destination | safeURL }}" {{ with .Title }}title="{{ . }}"{{ end }}{{ if strings.HasPrefix .Destination "http" }}target="_blank" rel="noopener"{{ end }}>{{ .Text | safeHTML }}</a> {{- with . -}}
<a href="{{ .Destination | safeURL }}" {{ with .Title }}title="{{ . }}"{{ end }}{{ if strings.HasPrefix .Destination "http" }}target="_blank" rel="noopener"{{ end }}>{{ .Text | safeHTML }}</a>
{{- end -}}

View File

@ -1,6 +1,11 @@
<head> <head>
<meta charset="utf-8" /> <meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
{{ if hugo.IsProduction -}}
<meta name="robots" content="index, follow" />
{{ else -}}
<meta name="robots" content="noindex, nofollow" />
{{ end -}}
{{ partialCached "favicons.html" . }} {{ partialCached "favicons.html" . }}
<title> <title>
{{- if .IsHome -}} {{- if .IsHome -}}
@ -12,6 +17,7 @@
</title> </title>
<meta name="description" content="{{ partial "utils/page-description.html" . }}" /> <meta name="description" content="{{ partial "utils/page-description.html" . }}" />
{{ partial "opengraph.html" . }} {{ partial "opengraph.html" . }}
{{ template "_internal/schema.html" . -}}
{{ partial "head-css.html" . }} {{ partial "head-css.html" . }}
<script> <script>
/* Initialize light/dark mode */ /* Initialize light/dark mode */

View File

@ -1,6 +1,7 @@
{{/* Table of Contents */}} {{/* Table of Contents */}}
{{/* TODO: toc bottom part should be able to hide */}} {{/* TODO: toc bottom part should be able to hide */}}
{{- $toc := .Params.toc | default true -}} {{- $toc := .Params.toc | default true -}}
{{- with site.Params.toc.disabled -}}{{ $toc = not . }}{{- end -}}
<nav class="order-last hidden w-64 shrink-0 xl:block print:hidden px-4" aria-label="table of contents"> <nav class="order-last hidden w-64 shrink-0 xl:block print:hidden px-4" aria-label="table of contents">
@ -22,9 +23,13 @@
{{ $borderClass = "" }} {{ $borderClass = "" }}
{{ end }} {{ end }}
{{/* TOC bottom part */}}
<div class="{{ $borderClass }} sticky bottom-0 flex flex-col items-start gap-2 pb-8 dark:border-neutral-800 contrast-more:border-t contrast-more:border-neutral-400 contrast-more:shadow-none contrast-more:dark:border-neutral-400"> <div class="{{ $borderClass }} sticky bottom-0 flex flex-col items-start gap-2 pb-8 dark:border-neutral-800 contrast-more:border-t contrast-more:border-neutral-400 contrast-more:shadow-none contrast-more:dark:border-neutral-400">
<a class="text-xs font-medium text-gray-500 hover:text-gray-900 dark:text-gray-400 dark:hover:text-gray-100 contrast-more:text-gray-800 contrast-more:dark:text-gray-50" href="{{ .Params.editURL }}">Edit this page on GitHub →</a> {{- if not site.Params.editURL.disabled -}}
{{- $editURL := urls.JoinPath site.Params.editURL.base .File.Path -}}
{{- with .Params.editURL -}}{{ $editURL = .Params.editURL }}{{- end -}}
<a class="text-xs font-medium text-gray-500 hover:text-gray-900 dark:text-gray-400 dark:hover:text-gray-100 contrast-more:text-gray-800 contrast-more:dark:text-gray-50" href="{{ $editURL }}" target="_blank" rel="noreferer">{{ i18n "article.edit_this_page" }}</a>
{{- end -}}
</div> </div>
</div> </div>
{{ end }} {{ end }}

View File

@ -3,19 +3,14 @@
name = "Hextra" name = "Hextra"
license = "MIT" license = "MIT"
licenselink = "https://github.com/yourname/yourtheme/blob/master/LICENSE" licenselink = "https://github.com/imfing/hextra/blob/main/LICENSE"
description = "" description = "Modern, versatile theme for building beautiful websites with Hugo"
homepage = "http://example.com/" homepage = "https://github.com/imfing/hextra/"
tags = [] demosite = ""
features = [] tags = ["Modern", "Elegant", "Blog", "Documentation"]
min_version = "0.115.3" features = ["Responsive", "Dark Mode", "Search", "Syntax Highlighting", "Multilingual"]
min_version = "0.111.0"
[author] [author]
name = "" name = "Xin"
homepage = "" homepage = "https://imfing.com"
# If porting an existing theme
[original]
name = ""
homepage = ""
repo = ""