WIP: fix some search stuff?

This commit is contained in:
a 2024-10-05 14:56:14 -05:00
parent 5e832261ed
commit 33b1bb942a
23 changed files with 62 additions and 24 deletions

View file

@ -11,8 +11,8 @@ const WORD_REGEX = /\b(\w*)[\W|\s|\b]?/gm
async function initSearch() {
try {
const indexJsonUrl = document.getElementById("baseUrl").dataset["baseUrl"] + "/index.json";
// const indexJsonUrl = "/wiki/index.json";
const indexJsonUrl = document.getElementById("baseUrl").dataset["baseUrl"] + "index.lunr.json";
console.log(indexJsonUrl);
const response = await fetch(indexJsonUrl);
pagesIndex = await response.json();
searchIndex = lunr(function () {

View file

@ -1,4 +1,4 @@
._default-list {
.layout-_default-list {
.list-header {
padding: 1em;
hr {display: none;}

View file

@ -1,4 +1,4 @@
._default-single {
.layout-_default-single {
.page-header {
padding: 2em 1em;
hr {display: none;}

View file

@ -1,4 +1,4 @@
.wiki-list {
.layout-wiki-list {
.subsections,
.subpages {
list-style: disc;

View file

@ -1,4 +1,4 @@
.wiki-single {
.layout-wiki-single {
.content {
padding-top: 0;
}

View file

@ -0,0 +1,7 @@
+++
title = "Search within /"
type = "_default"
layout = "search"
_build.list="never"
slug = "search"
+++

View file

@ -1,3 +0,0 @@
+++
title = "Search"
+++

View file

@ -0,0 +1,7 @@
+++
title = "Search within /wiki"
type = "_default"
layout = "search"
_build.list="never"
slug = "search"
+++

View file

@ -1,3 +0,0 @@
+++
title = "Search"
+++

4
unified.test.hugo/deploy Executable file
View file

@ -0,0 +1,4 @@
#!/bin/bash
rm -r public/
hugo
rsync -avz --delete public/ a@trwnh.com:/srv/http/trwnh.com

View file

@ -2,6 +2,8 @@ baseURL = "https://trwnh.com/"
languageCode = "en-us"
title = "~a"
markup.goldmark.renderer.unsafe = true
[markup.highlight]
codeFences = true
noClasses = false
@ -12,7 +14,13 @@ endLevel = 6
ordered = true
[outputs]
home = ["html", "json"]
home = ["html", "lunr"]
section = ["html", "lunr"]
[outputFormats.lunr]
baseName = "index.lunr"
isPlainText = true
mediaType = "application/json"
[taxonomies]
category = "categories"

View file

@ -1,5 +1,5 @@
{{ define "body" }}
<body class="_default _default-list">
<body class="layout-_default-list">
<main class="h-feed hfeed">
<header class="list-header section">
<div class="container">

View file

@ -2,10 +2,20 @@
{{ end }}
{{ define "body" }}
<body class="search search-list">
{{ partial "wiki/site-header.html" .}}
<body class="search-layout">
<header>
<div class="container">
<a href="/"><p>{{.Site.Title}}</p></a>
</div>
</header>
<main>
<div class="search-results section">
<header>
<div class="container">
<h1>{{.Title}}</h1>
{{ partial "search/search-form.html" .}}
</div>
</header>
<section class="search-results section">
<header>
<div class="container">
<h2 class="search-results__title"><span id="results-count"></span> <span id="results-count-text"></span> for "<span id="results-query"></span>"</h2>
@ -18,12 +28,12 @@
</ul>
</div>
</section>
</div>
</section>
</main>
<style>
a[href="#top"] {display: none;}
</style>
<div id="baseUrl" data-base-url="{{.Site.BaseURL}}"></div>
<div id="baseUrl" data-base-url="{{(trim .Path .File.ContentBaseName)}}"></div>
{{ partial "search/search-index.html" . }}
</body>
{{ end }}

View file

@ -0,0 +1,8 @@
{{- $.Scratch.Add "pagesIndex" slice -}}
{{- range $index, $page := (where .Site.RegularPages "Path" "like" (printf "^%s" .CurrentSection.Path)) -}}
{{- if gt (len $page.Content) 0 -}}
{{- $pageData := (dict "title" (or $page.Title $page.File.LogicalName) "href" $page.Permalink "content" $page.Plain) -}}
{{- $.Scratch.Add "pagesIndex" $pageData -}}
{{- end -}}
{{- end -}}
{{- $.Scratch.Get "pagesIndex" | jsonify -}}

View file

@ -1,5 +1,5 @@
{{ define "body" }}
<body class="_default _default-single">
<body class="layout-_default-single">
<main>
<article class="page h-entry hentry" {{- if .Param "autonumbering" }} autonumbering {{- end }}>
<header class="section page-header">

View file

@ -5,4 +5,4 @@
{{- $.Scratch.Add "pagesIndex" $pageData -}}
{{- end -}}
{{- end -}}
{{- $.Scratch.Get "pagesIndex" | jsonify -}}
{{- $.Scratch.Get "pagesIndex" | jsonify }}

View file

@ -1,4 +1,4 @@
<form id="search-form" action='{{ with .GetPage "/search" }}{{.Permalink}}{{end}}' method="get">
<form id="search-form" action='{{ with .GetPage (printf "%s%s" .CurrentSection.RelPermalink "search") }}{{.Permalink}}{{end}}' method="get">
<label hidden for="search-input">Search site</label>
<input id="search-input" type="text" name="query" placeholder="Type here to search">
<input id="search-submit" type="submit" value="search">

View file

@ -1,5 +1,5 @@
{{ define "body" }}
<body class="wiki wiki-list">
<body class="wiki layout-wiki-list">
{{ $currentFolderName := or $.File.ContentBaseName "index" }}
{{ partial "wiki/site-header.html" .}}
{{ partial "wiki/breadcrumbs.html" .}}

View file

@ -1,5 +1,5 @@
{{ define "body" }}
<body class="wiki wiki-single">
<body class="wiki layout-wiki-single">
{{ $currentFolderName := or $.File.ContentBaseName "index" }}
{{ partial "wiki/site-header.html" .}}
{{ partial "wiki/breadcrumbs.html" .}}