Compare commits

..

9 commits

Author SHA1 Message Date
70f8dc1571 torchlight: don't highlight series or tags 2024-01-15 18:28:33 -06:00
6da286c017 additional search tweaks 2024-01-15 18:12:56 -06:00
9223c6ca9e search styling work... 2024-01-15 17:07:23 -06:00
34fc5b5d6e initial work on search with lunr.js 2024-01-15 16:02:30 -06:00
39ff4c2b66 css: define new slightly-lighter color for code/pre elements 2024-01-15 15:14:08 -06:00
c11b975fba Revert "make --off-fg a little lighter to improve code/pre contrast"
This made non-code elements a bit too bright. Need to address code
elements more directly.

This reverts commit 16880cc516.
2024-01-15 15:06:39 -06:00
John Bowdre
710b493a74
Merge pull request #5 from jbowdre/preview
Further RSS improvements
2024-01-15 15:02:07 -06:00
f3570754cb rss: strip potentially-unsafe style elements (improve regex) 2024-01-15 14:57:42 -06:00
340e1f0cce rss: strip potentially-unsafe style elements 2024-01-15 14:53:35 -06:00
12 changed files with 3609 additions and 4 deletions

3475
assets/js/lunr.js Normal file

File diff suppressed because it is too large Load diff

44
assets/js/search.js Normal file
View file

@ -0,0 +1,44 @@
function displayResults (results, store) {
const searchResults = document.getElementById('results');
if (results.length) {
let resultList = '';
for (const n in results) {
const item = store[results[n].ref];
resultList += '<li><a href="' + item.url + '">' + item.title + '</a></li>'
if (item.description)
resultList += '<p>' + item.description + '</p>'
else
resultList += '<p>' + item.content.substring(0, 150) + '...</p>'
}
searchResults.innerHTML = resultList;
} else {
searchResults.innerHTML = 'No results found.';
}
}
const params = new URLSearchParams(window.location.search);
const query = params.get('query');
if (query) {
document.getElementById('search-query').setAttribute('value', query);
const idx = lunr(function () {
this.ref('id')
this.field('title', {
boost: 15
})
this.field('tags')
this.field('content', {
boost: 10
})
for (const key in window.store) {
this.add({
id: key,
title: window.store[key].title,
tags: window.store[key].tags,
content: window.store[key].content
})
}
})
const results = idx.search(query);
displayResults(results, window.store)
}

3
content/search/_index.md Normal file
View file

@ -0,0 +1,3 @@
---
title: Search me!
---

View file

@ -44,6 +44,7 @@
{{- $content := replaceRE "a href=\"(#.*?)\"" (printf "%s%s%s" "a href=\"" .Permalink "$1\"") .Content -}}
{{- $content = replaceRE "img src=\"(.*?)\"" (printf "%s%s%s" "img src=\"" .Permalink "$1\"") $content -}}
{{- $content = replaceRE "<svg.*</svg>" "" $content -}}
{{- $content = replaceRE `-moz-tab-size:\d;-o-tab-size:\d;tab-size:\d;?` "" $content -}}
<description>{{ $content | html }}</description>
</item>
{{ end }}

View file

@ -14,3 +14,4 @@
</li>
{{ end }}
</ul>
{{ partial "search-form.html" . }}

View file

@ -3,6 +3,7 @@
<p class="powered_by">{"powered_by": [{{- range $i, $link := .Site.Params.powerLinks }}{{ if $i }}, {{ end }}&quot;<a target="_blank" href="{{ $link.url }}">{{ $link.title }}</a>&quot;{{ end }}]}
<br>&lt;<a target="_blank" href="https://github.com/jbowdre/runtimeterror">view source</a>&gt;</p>
{{ partial "search-index.html" .}}
{{ if (findRE "<pre" .Content 1) }}
{{ $jsCopy := resources.Get "js/code-copy-button.js" | minify }}
<script src="{{ $jsCopy.RelPermalink }}"></script>

View file

@ -0,0 +1,5 @@
<form id="search"
action='{{ with .GetPage "/search" }}{{ .Permalink }}{{ end }}' method="get">
<input type="input" id="search-query" name="query" placeholder="grep -i" aria-label="search text">
<button type="submit" aria-label="search button"><i class="fa-solid fa-magnifying-glass"></i></button>
</form>

View file

@ -0,0 +1,17 @@
<script>
window.store = {
{{ range where .Site.Pages "Section" "posts" }}
"{{ .Permalink }}": {
"title": "{{ .Title }}",
"tags": [{{ range .Params.Tags }}"{{ . }}",{{ end }}],
"content": {{ .Content | plainify }},
"description": {{ .Description | plainify }},
"url": "{{ .Permalink }}"
},
{{ end }}
}
</script>
{{ $jsLunr := resources.Get "js/lunr.js" | minify }}
<script src="{{ $jsLunr.RelPermalink }}"></script>
{{ $jsSearch := resources.Get "js/search.js" | minify }}
<script src="{{ $jsSearch.RelPermalink }}"></script>

9
layouts/search/list.html Normal file
View file

@ -0,0 +1,9 @@
{{ define "main" }}
{{ partial "search-form.html" . }}
<br>
<ul id="results">
<li>
Enter a keyword above to search this site.
</li>
</ul>
{{ end }}

View file

@ -1,3 +1,8 @@
/* color overrides */
:root {
--code: var(--base06);
}
/* override page max-width */
.page {
max-width: 72rem;
@ -203,4 +208,46 @@ ul.pagination li {
small[style^="opacity: .5"] {
opacity: 1 !important;
}
}
/* code overrides */
pre,
code,
kbd,
samp {
color: var(--code);
}
/* search box styling */
form {
display: flex;
flex-direction: row;
border-radius: 0.25rem;
outline: 0.25rem solid var(--bg);
}
input {
flex-grow: 2;
border: none;
background-color: var(--off-bg);
color: var(--off-fg);
height: 1.5rem;
border-radius: 0.25rem;
padding-left: 0.5rem;
font-family: var(--font-monospace);
}
input:focus {
outline: none;
}
form:focus-within {
outline: 1px solid var(--logo);
}
form button {
outline: none;
border: none;
background-color: var(--off-bg);
color: var(--link);
}

View file

@ -6,9 +6,9 @@
--base01: #282828; /* off-bg */
--base02: #383838; /* inner-bg */
--base03: #585858; /* muted */
--base04: #cfcfcf; /* off-fg */
--base04: #abaaaa; /* off-fg */
--base05: #d8d8d8; /* fg */
--base06: #e8e8e8;
--base06: #cfcfcf; /* code */
--base07: #5f8700; /* user prompt */
--base08: #ab4642; /* root prompt */
--base09: #dc9656;

View file

@ -58,7 +58,9 @@ module.exports = {
// appear, the file will be ignored.
excludePatterns: [
'/node_modules/',
'/vendor/'
'/vendor/',
'/series/',
'/tags/'
]
}
}