Simplified search result templates

This commit is contained in:
squidfunk 2020-02-11 22:04:16 +01:00
parent 6dba046eae
commit b891fe90fb
6 changed files with 36 additions and 140 deletions

View File

@ -52,7 +52,7 @@ export function renderClipboard(
<button <button
class={css.container} class={css.container}
title={translate("clipboard.copy")} title={translate("clipboard.copy")}
data-clipboard-target={`#${id} pre, #${id} code`} data-clipboard-target={`#${id} code`}
>&#xE14D;</button> >&#xE14D;</button>
) )
} }

View File

@ -1,23 +0,0 @@
/*
* Copyright (c) 2016-2020 Martin Donath <martin.donath@squidfunk.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
export * from "./result"

View File

@ -21,7 +21,7 @@
*/ */
import { h } from "extensions" import { h } from "extensions"
import { ArticleDocument } from "modules" import { SearchResult } from "modules"
import { truncate } from "utilities" import { truncate } from "utilities"
/* ---------------------------------------------------------------------------- /* ----------------------------------------------------------------------------
@ -32,8 +32,10 @@ import { truncate } from "utilities"
* CSS classes * CSS classes
*/ */
const css = { const css = {
item: "md-search-result__item",
link: "md-search-result__link", link: "md-search-result__link",
article: "md-search-result__article md-search-result__article--document", article: "md-search-result__article md-search-result__article--document",
section: "md-search-result__article",
title: "md-search-result__title", title: "md-search-result__title",
teaser: "md-search-result__teaser" teaser: "md-search-result__teaser"
} }
@ -43,24 +45,32 @@ const css = {
* ------------------------------------------------------------------------- */ * ------------------------------------------------------------------------- */
/** /**
* Render an article document * Render a search result
* *
* @param article - Article document * @param result - Search result
* *
* @return HTML element * @return HTML element
*/ */
export function renderArticleDocument( export function renderSearchResult(
{ location, title, text }: ArticleDocument { article, sections }: SearchResult
): HTMLElement { ): HTMLElement {
const children = [article, ...sections].map(document => {
const { location, title, text } = document
return (
<a href={location} class={css.link} tabIndex={-1}>
<article class={"parent" in document ? css.section : css.article}>
<h1 class={css.title}>{title}</h1>
{text.length
? <p class={css.teaser}>{truncate(text, 320)}</p>
: undefined
}
</article>
</a>
)
})
return ( return (
<a href={location} class={css.link} tabIndex={-1}> <li class={css.item}>
<article class={css.article}> {...children}
<h1 class={css.title}>{title}</h1> </li>
{text.length
? <p class={css.teaser}>{truncate(text, 320)}</p>
: undefined
}
</article>
</a>
) )
} }

View File

@ -1,23 +0,0 @@
/*
* Copyright (c) 2016-2020 Martin Donath <martin.donath@squidfunk.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
export * from "./_"

View File

@ -1,66 +0,0 @@
/*
* Copyright (c) 2016-2020 Martin Donath <martin.donath@squidfunk.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
* IN THE SOFTWARE.
*/
import { h } from "extensions"
import { SectionDocument } from "modules"
import { truncate } from "utilities"
/* ----------------------------------------------------------------------------
* Data
* ------------------------------------------------------------------------- */
/**
* CSS classes
*/
const css = {
link: "md-search-result__link",
article: "md-search-result__article",
title: "md-search-result__title",
teaser: "md-search-result__teaser"
}
/* ----------------------------------------------------------------------------
* Functions
* ------------------------------------------------------------------------- */
/**
* Render a section document
*
* @param section - Section document
*
* @return HTML element
*/
export function renderSectionDocument(
{ location, title, text }: SectionDocument
): HTMLElement {
return (
<a href={location} class={css.link} tabIndex={-1}>
<article class={css.article}>
<h1 class={css.title}>{title}</h1>
{text.length
? <p class={css.teaser}>{truncate(text, 320)}</p>
: undefined
}
</article>
</a>
)
}

View File

@ -21,10 +21,6 @@
*/ */
import { h } from "extensions" import { h } from "extensions"
import { SearchResult } from "modules"
import { renderArticleDocument } from "../article"
import { renderSectionDocument } from "../section"
/* ---------------------------------------------------------------------------- /* ----------------------------------------------------------------------------
* Data * Data
@ -34,7 +30,8 @@ import { renderSectionDocument } from "../section"
* CSS classes * CSS classes
*/ */
const css = { const css = {
item: "md-search-result__item" wrapper: "md-typeset__scrollwrap",
table: "md-typeset__table"
} }
/* ---------------------------------------------------------------------------- /* ----------------------------------------------------------------------------
@ -42,19 +39,20 @@ const css = {
* ------------------------------------------------------------------------- */ * ------------------------------------------------------------------------- */
/** /**
* Render a search result * Render a table wrapper
* *
* @param result - Search result * @param table - Table element
* *
* @return HTML element * @return HTML element
*/ */
export function renderSearchResult( export function renderTable(
{ article, sections }: SearchResult table: HTMLTableElement
): HTMLElement { ): HTMLElement {
return ( return (
<li class={css.item}> <div class={css.wrapper}>
{renderArticleDocument(article)} <div class={css.table}>
{...sections.map(renderSectionDocument)} {table}
</li> </div>
</div>
) )
} }