Runway 1.0.0
This commit is contained in:
commit
dcf819146b
1372 files changed
+188168
No files matched your search
@@ -0,0 +1,2 @@
|
||||
/* Runway Search plugin: added to every page of a site with search highlighting on. Loads highlight.js only when the address carries the #rw-hl= marker of a search result link, now or after a hashchange. Kept tiny on purpose: it is fetched with every page. */
|
||||
(function(){function l(){if(window.__rwHl||location.hash.indexOf('rw-hl=')<0)return;window.__rwHl=1;var s=document.createElement('script');s.src='/__plugin/search/static/highlight.js?v=2.3.0';document.head.appendChild(s)}l();addEventListener('hashchange',l)})();
|
||||
@@ -0,0 +1,9 @@
|
||||
/* Runway Search plugin — how the page a search result opened shows the matched words (search 2.1.0+).
|
||||
Added by highlight.js before the site's own stylesheets, only when the visitor came from a result, so a site
|
||||
restyles it with its own rule, e.g. ::highlight(rw-search) { background-color: #cfe2ff; }
|
||||
Only colour, background and text decoration apply to a highlight; layout properties are ignored. */
|
||||
/* Dark text on the yellow, set explicitly: a dark theme's light text would be unreadable on it. */
|
||||
::highlight(rw-search) {
|
||||
background-color: #ffe066;
|
||||
color: #1a1a1a;
|
||||
}
|
||||
@@ -0,0 +1,192 @@
|
||||
/* Runway Search plugin — highlights, on the page a search result opened, the words the search matched there.
|
||||
Served at /__plugin/search/static/highlight.js and loaded only by highlight-loader.js (which every page of a site
|
||||
with highlighting on carries), and only when the address carries the marker #rw-hl=<words> that a result link
|
||||
adds (search 2.1.0+).
|
||||
|
||||
What it does:
|
||||
- reads the words from the marker (percent-encoded, separated by spaces) on load and on every hashchange;
|
||||
- highlights each whole-word occurrence, ignoring case, with the CSS Custom Highlight API: no element is added
|
||||
or changed, so a site script holding references to the page's nodes is unaffected;
|
||||
- looks inside the page's content slot (<main id="content">, else <main>, else <body> without its <header>,
|
||||
<nav>, <footer> and <aside>), skipping scripts, styles, form fields and the search box's own results; at
|
||||
most 200 occurrences;
|
||||
- scrolls to the first occurrence a visitor can see (a match inside a closed tab or <details> stays highlighted
|
||||
and shows when it opens);
|
||||
- removes the marker from the address with history.replaceState, so a reload or a bookmark gets the plain URL.
|
||||
|
||||
The style is the ::highlight(rw-search) rule in highlight.css, added before the site's own stylesheets so a
|
||||
site rule for ::highlight(rw-search) wins. A browser without the API (Firefox before 140, Safari before 17.2)
|
||||
highlights nothing; the marker is still removed. */
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
var KEY = 'rw-hl=';
|
||||
var NAME = 'rw-search';
|
||||
var MAX_RANGES = 200;
|
||||
var MAX_WORDS = 20;
|
||||
var SKIP = { SCRIPT: 1, STYLE: 1, NOSCRIPT: 1, TEMPLATE: 1, TEXTAREA: 1, INPUT: 1, SELECT: 1, OPTION: 1, svg: 1 };
|
||||
|
||||
function wordsFromHash() {
|
||||
var hash = location.hash;
|
||||
var at = hash.indexOf(KEY);
|
||||
if (at < 0) {
|
||||
return null;
|
||||
}
|
||||
var raw = hash.substring(at + KEY.length);
|
||||
var amp = raw.indexOf('&');
|
||||
if (amp >= 0) {
|
||||
raw = raw.substring(0, amp);
|
||||
}
|
||||
var text;
|
||||
try {
|
||||
text = decodeURIComponent(raw);
|
||||
} catch (e) {
|
||||
return [];
|
||||
}
|
||||
var seen = {};
|
||||
var words = [];
|
||||
text.split(/\s+/).forEach(function (w) {
|
||||
var word = w.trim().toLowerCase();
|
||||
if (word && word.length <= 64 && !seen[word] && words.length < MAX_WORDS) {
|
||||
seen[word] = 1;
|
||||
words.push(word);
|
||||
}
|
||||
});
|
||||
return words;
|
||||
}
|
||||
|
||||
/** Drops the marker from the address, keeping any other fragment, without adding a history entry. */
|
||||
function clearMarker() {
|
||||
var hash = location.hash;
|
||||
var at = hash.indexOf(KEY);
|
||||
if (at < 0 || !history.replaceState) {
|
||||
return;
|
||||
}
|
||||
var rest = hash.substring(at + KEY.length);
|
||||
var amp = rest.indexOf('&');
|
||||
var before = hash.substring(1, at).replace(/&$/, '');
|
||||
var after = amp >= 0 ? rest.substring(amp + 1) : '';
|
||||
var kept = [before, after].filter(Boolean).join('&');
|
||||
try {
|
||||
history.replaceState(history.state, '', location.pathname + location.search + (kept ? '#' + kept : ''));
|
||||
} catch (e) {
|
||||
// A document that cannot rewrite its address (about:srcdoc, blob:) still gets the highlight.
|
||||
}
|
||||
}
|
||||
|
||||
function escapeRegExp(s) {
|
||||
return s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
|
||||
}
|
||||
|
||||
/**
|
||||
* One pattern for all words, longest first, matching only whole words (letters, digits and marks). The server
|
||||
* lowercases with Java's rules, which turn the Turkish capital I with a dot into "i" plus a combining dot; the
|
||||
* browser's case-insensitive match never folds that capital to anything, so every "i" also accepts it.
|
||||
*/
|
||||
function pattern(words) {
|
||||
var alternatives = words.slice().sort(function (a, b) { return b.length - a.length; }).map(function (w) {
|
||||
return escapeRegExp(w.replace(/i\u0307/g, 'i')).replace(/i/g, '[i\u0130]');
|
||||
});
|
||||
return new RegExp('(?<![\\p{L}\\p{N}\\p{M}])(?:' + alternatives.join('|') + ')(?![\\p{L}\\p{N}\\p{M}])', 'giu');
|
||||
}
|
||||
|
||||
function root() {
|
||||
return document.getElementById('content') || document.querySelector('main') || document.body;
|
||||
}
|
||||
|
||||
/** Page chrome, skipped when the page has no content slot and the whole <body> is searched. */
|
||||
var CHROME = { HEADER: 1, NAV: 1, FOOTER: 1, ASIDE: 1 };
|
||||
|
||||
function rejectNode(node, wholeBody) {
|
||||
for (var el = node.parentElement; el; el = el.parentElement) {
|
||||
if (SKIP[el.tagName] || SKIP[el.nodeName] || (wholeBody && CHROME[el.tagName]) || el.isContentEditable
|
||||
|| (el.classList && el.classList.contains('rw-search-hits'))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function ranges(words) {
|
||||
var re = pattern(words);
|
||||
var found = [];
|
||||
var start = root();
|
||||
var wholeBody = start === document.body;
|
||||
var walker = document.createTreeWalker(start, NodeFilter.SHOW_TEXT, {
|
||||
acceptNode: function (node) {
|
||||
return node.nodeValue.trim() && !rejectNode(node, wholeBody)
|
||||
? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_REJECT;
|
||||
}
|
||||
});
|
||||
var node;
|
||||
while (found.length < MAX_RANGES && (node = walker.nextNode())) {
|
||||
re.lastIndex = 0;
|
||||
var m;
|
||||
while (found.length < MAX_RANGES && (m = re.exec(node.nodeValue))) {
|
||||
var range = document.createRange();
|
||||
range.setStart(node, m.index);
|
||||
range.setEnd(node, m.index + m[0].length);
|
||||
found.push(range);
|
||||
}
|
||||
}
|
||||
return found;
|
||||
}
|
||||
|
||||
function visible(range) {
|
||||
var el = range.startContainer.parentElement;
|
||||
if (!el) {
|
||||
return false;
|
||||
}
|
||||
if (el.checkVisibility) {
|
||||
return el.checkVisibility({ visibilityProperty: true, opacityProperty: false });
|
||||
}
|
||||
return range.getClientRects().length > 0;
|
||||
}
|
||||
|
||||
function addStyle() {
|
||||
if (document.getElementById('rw-search-highlight-css')) {
|
||||
return;
|
||||
}
|
||||
var link = document.createElement('link');
|
||||
link.id = 'rw-search-highlight-css';
|
||||
link.rel = 'stylesheet';
|
||||
link.href = '/__plugin/search/static/highlight.css?v=2.3.0';
|
||||
// First in <head>, so any ::highlight(rw-search) rule of the site comes later and wins.
|
||||
document.head.insertBefore(link, document.head.firstChild);
|
||||
}
|
||||
|
||||
function run() {
|
||||
var words = wordsFromHash();
|
||||
if (words === null) {
|
||||
return;
|
||||
}
|
||||
clearMarker();
|
||||
if (!window.CSS || !CSS.highlights || typeof Highlight === 'undefined' || !words.length) {
|
||||
return;
|
||||
}
|
||||
addStyle();
|
||||
var found = ranges(words);
|
||||
CSS.highlights.delete(NAME);
|
||||
if (!found.length) {
|
||||
return;
|
||||
}
|
||||
CSS.highlights.set(NAME, new Highlight(...found));
|
||||
for (var i = 0; i < found.length; i++) {
|
||||
if (visible(found[i])) {
|
||||
found[i].startContainer.parentElement.scrollIntoView({ block: 'center' });
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function start() {
|
||||
run();
|
||||
addEventListener('hashchange', run);
|
||||
}
|
||||
|
||||
if (document.readyState === 'loading') {
|
||||
document.addEventListener('DOMContentLoaded', start);
|
||||
} else {
|
||||
start();
|
||||
}
|
||||
})();
|
||||
@@ -0,0 +1,82 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<meta name="robots" content="noindex">
|
||||
<title>Search plugin — help & reference</title>
|
||||
<link rel="stylesheet" href="/__plugin/search/static/search.css">
|
||||
<style>
|
||||
body { max-width: 46rem; margin: 2rem auto; padding: 0 1rem;
|
||||
font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: #1a1a1a; line-height: 1.5; }
|
||||
h1 { font-size: 1.6rem; } h2 { font-size: 1.2rem; margin-top: 1.75rem; }
|
||||
code { background: #f3f3f3; padding: .1rem .3rem; border-radius: .25rem; }
|
||||
pre { background: #f6f8fa; padding: .75rem 1rem; border-radius: .375rem; overflow: auto; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Search — help & reference</h1>
|
||||
<p>The Search plugin adds on-site search to your site: an embeddable, query-aware <strong>search box</strong>
|
||||
(a content widget) backed by a pluggable engine. The built-in engine searches the titles, descriptions and text
|
||||
of your published pages and content (entries other plugins publish, …) and needs no setup — search works the moment the plugin
|
||||
is installed and enabled. A change you make in the console (a page saved, an entry published, a setting
|
||||
changed) is searchable at once.</p>
|
||||
|
||||
<h2>Install a ready-made search results page</h2>
|
||||
<p>On the Search settings page, the <strong>Search page</strong> card installs a ready-made results page (at
|
||||
<code>/search</code>) carrying the box. It then becomes an <strong>ordinary site page</strong> — it appears
|
||||
under <em>Pages</em>, and you can edit its template, restyle it, move it or give it a different URL. Installing
|
||||
never overwrites an existing page, and it follows your site's editorial rules: on a site whose pages need
|
||||
review, the page waits in the review queue; when the quality checks block publishing, it is created as a draft
|
||||
for you to fix in the page editor. The button tells you which happened.</p>
|
||||
|
||||
<h2>Or put a search box on any page</h2>
|
||||
<p>In any page (or your master chrome), add an anchor where the box should appear:</p>
|
||||
<pre><div id="site-search" data-widget="search/box"></div></pre>
|
||||
<p>The <code>id</code> and <code>data-widget</code> must be on the <em>same</em> element. The box submits
|
||||
<code>?q=</code> to your results page (the <strong>Results page path</strong> setting, default
|
||||
<code>/search</code>). The widget is query-aware: when a page carrying it is opened with a non-blank
|
||||
<code>q</code>, it renders the ranked results <em>inline below the box</em>. Everything is styled by this
|
||||
plugin's stylesheet (<code>/__plugin/search/static/search.css</code>) — override any <code>.rw-search*</code>
|
||||
rule from your own CSS to match your theme.</p>
|
||||
|
||||
<h2>Settings (per site)</h2>
|
||||
<ul>
|
||||
<li><strong>Enable search</strong> — turn the box (and its inline results) on or off.</li>
|
||||
<li><strong>Maximum results</strong> — how many hits the results show (1–100).</li>
|
||||
<li><strong>Results page path</strong> — where the box submits <code>?q=</code> (default <code>/search</code>);
|
||||
change it if you move or rename the results page.</li>
|
||||
<li><strong>Search box placeholder</strong> — the greyed-out prompt text in the box.</li>
|
||||
<li><strong>Excluded content</strong> — pages (by their slug) and entries (by their id) that search leaves out,
|
||||
one per line.</li>
|
||||
<li><strong>Record searches with no results</strong> — off by default; see below.</li>
|
||||
<li><strong>Keep unrepeated terms for (days)</strong> — how long a term nobody searches for again stays on
|
||||
the list (default 90).</li>
|
||||
</ul>
|
||||
|
||||
<h2>Searches with no results</h2>
|
||||
<p>Turn on <strong>Record searches with no results</strong> and the settings page lists what visitors searched for
|
||||
on your site and did not find — most frequent first, with how often and when it was last searched. Each entry
|
||||
is a hint: a page you could add, a title or description that should mention the word visitors use, or a
|
||||
redirect from an old name.</p>
|
||||
<p>It is <strong>off by default</strong> because a search term is whatever a visitor typed, and people sometimes type
|
||||
names, email addresses or numbers. When it is on, only the term, a count and the last time are kept — never an
|
||||
IP address, a user or a session. Terms that look like an email address or a phone number are not kept at all.
|
||||
Letter case and extra spaces are ignored, so "Opening Hours" and "opening hours" count together.
|
||||
The list keeps at most 500 terms (the rarest make room for new ones) and forgets a term nobody has searched
|
||||
for in the number of days you set. <strong>Clear list</strong> forgets everything at once; it cannot be
|
||||
undone. If you turn recording off, the list stays until you clear it or its terms age out.</p>
|
||||
<p>The list is kept in your site's folder, so a full backup carries it. A <strong>transfer copy</strong> of the site
|
||||
(the download meant for someone outside your organisation) leaves it out, because it is what visitors typed.</p>
|
||||
<h2>Rebuild the index</h2>
|
||||
<p>Search notices every change made through the console by itself. If files were changed some other way (copied in
|
||||
by hand), <strong>Rebuild index</strong> on the Search settings page re-reads everything now and tells you how
|
||||
many items the index holds.</p>
|
||||
|
||||
<h2>A better engine</h2>
|
||||
<p>Search is backed by a <code>SiteSearchEngine</code> extension point. Installing a companion plugin such as
|
||||
<strong>search-lucene</strong> (which builds a full-text index over your page bodies) transparently upgrades
|
||||
the engine — the box and the inline results are unchanged. The <em>Active engine</em> line on the Search
|
||||
settings page shows which engine is serving your site.</p>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,88 @@
|
||||
/* Runway Search plugin — styles for the embeddable search box and the /search results page.
|
||||
Served at /__plugin/search/static/search.css. Deliberately minimal and neutral so it inherits the site's
|
||||
look; a site can override any .rw-search* rule from its own stylesheet. */
|
||||
|
||||
.rw-search-box,
|
||||
.rw-search-form {
|
||||
display: flex;
|
||||
gap: .5rem;
|
||||
align-items: center;
|
||||
max-width: 40rem;
|
||||
}
|
||||
|
||||
.rw-search-box-input,
|
||||
.rw-search-input {
|
||||
flex: 1 1 auto;
|
||||
padding: .5rem .75rem;
|
||||
border: 1px solid #ccc;
|
||||
border-radius: .375rem;
|
||||
font-size: 1rem;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.rw-search-box-submit,
|
||||
.rw-search-submit {
|
||||
padding: .5rem 1rem;
|
||||
border: 1px solid transparent;
|
||||
border-radius: .375rem;
|
||||
background: #0d6efd;
|
||||
color: #fff;
|
||||
cursor: pointer;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.rw-search-box-submit:hover,
|
||||
.rw-search-submit:hover {
|
||||
filter: brightness(.95);
|
||||
}
|
||||
|
||||
/* Results page */
|
||||
.rw-search-main {
|
||||
max-width: 46rem;
|
||||
margin: 2rem auto;
|
||||
padding: 0 1rem;
|
||||
font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
|
||||
color: #1a1a1a;
|
||||
}
|
||||
|
||||
.rw-search-title {
|
||||
font-size: 1.5rem;
|
||||
margin: 0 0 1rem;
|
||||
}
|
||||
|
||||
.rw-search-form {
|
||||
margin-bottom: 1.5rem;
|
||||
}
|
||||
|
||||
.rw-search-count,
|
||||
.rw-search-empty {
|
||||
color: #555;
|
||||
margin: 0 0 1rem;
|
||||
}
|
||||
|
||||
.rw-search-hits {
|
||||
list-style: none;
|
||||
padding: 0;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.rw-search-hit {
|
||||
padding: .75rem 0;
|
||||
border-top: 1px solid #eee;
|
||||
}
|
||||
|
||||
.rw-search-hit-link {
|
||||
font-size: 1.125rem;
|
||||
text-decoration: none;
|
||||
color: #0d6efd;
|
||||
}
|
||||
|
||||
.rw-search-hit-link:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.rw-search-hit-snippet {
|
||||
margin: .25rem 0 0;
|
||||
color: #555;
|
||||
font-size: .95rem;
|
||||
}
|
||||
Reference in new issue
Block a user