From f4e628a0b49fbe122723662d1f35981e18c9ba15 Mon Sep 17 00:00:00 2001 From: Gon Pombo Date: Tue, 16 May 2023 16:36:55 -0300 Subject: [PATCH] Feat/improvemnts (#10) * add sdk context to search * open external links on a new tab * improve search with sdk6 * cards styles * update copyright * add playground html * reuse fn --- assets/_home.scss | 12 ++++++++++- assets/search.js | 20 +++++++++++++++-- layouts/_default/_markup/render-link.html | 4 +++- layouts/partials/docs/html-footer.html | 2 +- layouts/shortcodes/playground.html | 26 +++++++++++++++++++++++ 5 files changed, 59 insertions(+), 5 deletions(-) create mode 100644 layouts/shortcodes/playground.html diff --git a/assets/_home.scss b/assets/_home.scss index a05e56d..7167254 100644 --- a/assets/_home.scss +++ b/assets/_home.scss @@ -41,6 +41,11 @@ margin-right: 20px; padding: 20px; text-align: left; + a:first-child { + display: flex; + flex-direction: column; + height: 100%; + } * { color: white @@ -57,7 +62,6 @@ .card-info { flex: 1 1; width: 100%; - padding-bottom: 30px; } .card-cta { @@ -82,6 +86,12 @@ } } + @media (max-width: 900px) { + .home .user-card .card-img { + padding: 0px !important; + } + } + @media (max-width: 768px) { .home { .book-search { diff --git a/assets/search.js b/assets/search.js index 2a30cec..7eee5b2 100644 --- a/assets/search.js +++ b/assets/search.js @@ -119,19 +119,35 @@ resultCard(`Not Found`, `Sorry, we couldn't find any matches. Try searching for a different keyword`) return } + const currentPathname = window.location.pathname + searchHits.forEach((hit) => { const document = documents.get(Number(hit.ref)) if (!document) return + if ((isSdk6(currentPathname) && isSdk7(document.href)) + || (isSdk7(currentPathname) && isSdk6(document.href)) + ) return const highlightedContent = highlightContent(document.content, hit) resultCard(document.title, highlightedContent, document.href) }); } + function isSdk6(href) { + return href && href.includes('creator/development-guide') && !href.includes('sdk7') + } + + function isSdk7(href) { + return href && href.includes('creator/development-guide/sdk7') + } + function resultCard(title, content, href) { - const li = element('
  • '); + const li = element('
  • '); if (href) li.querySelector('a').href = href; - li.querySelector('h4').textContent = title; + const sdk6 = isSdk6(href) && ' [SDK 6]' + const sdk7 = isSdk7(href) && ' [SDK 7]' + const sdkContext = sdk6 || sdk7 || '' li.querySelector('span').innerHTML = content + li.querySelector('p').innerHTML = `${title}${sdkContext}` results.appendChild(li); } diff --git a/layouts/_default/_markup/render-link.html b/layouts/_default/_markup/render-link.html index 464fa1a..a092214 100644 --- a/layouts/_default/_markup/render-link.html +++ b/layouts/_default/_markup/render-link.html @@ -1,7 +1,9 @@ {{- if .Page.Site.Params.BookPortableLinks -}} {{- template "portable-link" . -}} {{- else -}} - {{ .Text | safeHTML }} + + {{ .Text | safeHTML }} + {{- end -}} {{- define "portable-link" -}} diff --git a/layouts/partials/docs/html-footer.html b/layouts/partials/docs/html-footer.html index b6ac1dd..a1496c1 100644 --- a/layouts/partials/docs/html-footer.html +++ b/layouts/partials/docs/html-footer.html @@ -31,6 +31,6 @@ - + \ No newline at end of file diff --git a/layouts/shortcodes/playground.html b/layouts/shortcodes/playground.html new file mode 100644 index 0000000..5e2654a --- /dev/null +++ b/layouts/shortcodes/playground.html @@ -0,0 +1,26 @@ + + +
    + {{ .Inner | markdownify }} + Try in playground +