mirror of
https://github.com/squidfunk/mkdocs-material.git
synced 2024-06-14 11:52:32 +03:00
Simplified search result templates
This commit is contained in:
parent
6dba046eae
commit
b891fe90fb
@ -52,7 +52,7 @@ export function renderClipboard(
|
||||
<button
|
||||
class={css.container}
|
||||
title={translate("clipboard.copy")}
|
||||
data-clipboard-target={`#${id} pre, #${id} code`}
|
||||
data-clipboard-target={`#${id} code`}
|
||||
></button>
|
||||
)
|
||||
}
|
||||
|
@ -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"
|
@ -21,7 +21,7 @@
|
||||
*/
|
||||
|
||||
import { h } from "extensions"
|
||||
import { ArticleDocument } from "modules"
|
||||
import { SearchResult } from "modules"
|
||||
import { truncate } from "utilities"
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
@ -32,8 +32,10 @@ import { truncate } from "utilities"
|
||||
* CSS classes
|
||||
*/
|
||||
const css = {
|
||||
item: "md-search-result__item",
|
||||
link: "md-search-result__link",
|
||||
article: "md-search-result__article md-search-result__article--document",
|
||||
section: "md-search-result__article",
|
||||
title: "md-search-result__title",
|
||||
teaser: "md-search-result__teaser"
|
||||
}
|
||||
@ -43,18 +45,20 @@ const css = {
|
||||
* ------------------------------------------------------------------------- */
|
||||
|
||||
/**
|
||||
* Render an article document
|
||||
* Render a search result
|
||||
*
|
||||
* @param article - Article document
|
||||
* @param result - Search result
|
||||
*
|
||||
* @return HTML element
|
||||
*/
|
||||
export function renderArticleDocument(
|
||||
{ location, title, text }: ArticleDocument
|
||||
export function renderSearchResult(
|
||||
{ article, sections }: SearchResult
|
||||
): HTMLElement {
|
||||
const children = [article, ...sections].map(document => {
|
||||
const { location, title, text } = document
|
||||
return (
|
||||
<a href={location} class={css.link} tabIndex={-1}>
|
||||
<article class={css.article}>
|
||||
<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>
|
||||
@ -63,4 +67,10 @@ export function renderArticleDocument(
|
||||
</article>
|
||||
</a>
|
||||
)
|
||||
})
|
||||
return (
|
||||
<li class={css.item}>
|
||||
{...children}
|
||||
</li>
|
||||
)
|
||||
}
|
@ -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 "./_"
|
@ -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>
|
||||
)
|
||||
}
|
@ -21,10 +21,6 @@
|
||||
*/
|
||||
|
||||
import { h } from "extensions"
|
||||
import { SearchResult } from "modules"
|
||||
|
||||
import { renderArticleDocument } from "../article"
|
||||
import { renderSectionDocument } from "../section"
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
* Data
|
||||
@ -34,7 +30,8 @@ import { renderSectionDocument } from "../section"
|
||||
* CSS classes
|
||||
*/
|
||||
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
|
||||
*/
|
||||
export function renderSearchResult(
|
||||
{ article, sections }: SearchResult
|
||||
export function renderTable(
|
||||
table: HTMLTableElement
|
||||
): HTMLElement {
|
||||
return (
|
||||
<li class={css.item}>
|
||||
{renderArticleDocument(article)}
|
||||
{...sections.map(renderSectionDocument)}
|
||||
</li>
|
||||
<div class={css.wrapper}>
|
||||
<div class={css.table}>
|
||||
{table}
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
Loading…
Reference in New Issue
Block a user