mirror of
https://github.com/alex-shpak/hugo-book.git
synced 2025-07-16 11:41:27 +00:00
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
This commit is contained in:
parent
b101211c0c
commit
f4e628a0b4
@ -41,6 +41,11 @@
|
|||||||
margin-right: 20px;
|
margin-right: 20px;
|
||||||
padding: 20px;
|
padding: 20px;
|
||||||
text-align: left;
|
text-align: left;
|
||||||
|
a:first-child {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
* {
|
* {
|
||||||
color: white
|
color: white
|
||||||
@ -57,7 +62,6 @@
|
|||||||
.card-info {
|
.card-info {
|
||||||
flex: 1 1;
|
flex: 1 1;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
padding-bottom: 30px;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.card-cta {
|
.card-cta {
|
||||||
@ -82,6 +86,12 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@media (max-width: 900px) {
|
||||||
|
.home .user-card .card-img {
|
||||||
|
padding: 0px !important;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@media (max-width: 768px) {
|
@media (max-width: 768px) {
|
||||||
.home {
|
.home {
|
||||||
.book-search {
|
.book-search {
|
||||||
|
@ -119,19 +119,35 @@
|
|||||||
resultCard(`Not Found`, `Sorry, we couldn't find any matches. Try searching for a different keyword`)
|
resultCard(`Not Found`, `Sorry, we couldn't find any matches. Try searching for a different keyword`)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
const currentPathname = window.location.pathname
|
||||||
|
|
||||||
searchHits.forEach((hit) => {
|
searchHits.forEach((hit) => {
|
||||||
const document = documents.get(Number(hit.ref))
|
const document = documents.get(Number(hit.ref))
|
||||||
if (!document) return
|
if (!document) return
|
||||||
|
if ((isSdk6(currentPathname) && isSdk7(document.href))
|
||||||
|
|| (isSdk7(currentPathname) && isSdk6(document.href))
|
||||||
|
) return
|
||||||
const highlightedContent = highlightContent(document.content, hit)
|
const highlightedContent = highlightContent(document.content, hit)
|
||||||
resultCard(document.title, highlightedContent, document.href)
|
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) {
|
function resultCard(title, content, href) {
|
||||||
const li = element('<li><a href><h4></h4><span></span></a></li>');
|
const li = element('<li><a href><p></p><span></span></a></li>');
|
||||||
if (href) li.querySelector('a').href = href;
|
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('span').innerHTML = content
|
||||||
|
li.querySelector('p').innerHTML = `<span style="font-size: 18px; font-weight: 700;">${title}</span>${sdkContext}`
|
||||||
results.appendChild(li);
|
results.appendChild(li);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
{{- if .Page.Site.Params.BookPortableLinks -}}
|
{{- if .Page.Site.Params.BookPortableLinks -}}
|
||||||
{{- template "portable-link" . -}}
|
{{- template "portable-link" . -}}
|
||||||
{{- else -}}
|
{{- else -}}
|
||||||
<a href="{{ .Destination | safeURL }}"{{ with .Title}} title="{{ . }}"{{ end }}>{{ .Text | safeHTML }}</a>
|
<a href="{{ .Destination | safeURL }}"{{ with .Title}} title="{{ . }}"{{ end }}{{ if or (in .Destination ":") (strings.HasPrefix .Destination "//") }} target="_blank" {{ end }}>
|
||||||
|
{{ .Text | safeHTML }}
|
||||||
|
</a>
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
|
|
||||||
{{- define "portable-link" -}}
|
{{- define "portable-link" -}}
|
||||||
|
@ -31,6 +31,6 @@
|
|||||||
<i class="social-icon twitter" ></i>
|
<i class="social-icon twitter" ></i>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
<div class="copyright">© 2022 Decentraland</div>
|
<div class="copyright">© 2023 Decentraland</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
26
layouts/shortcodes/playground.html
Normal file
26
layouts/shortcodes/playground.html
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
<style>
|
||||||
|
.code-playground {
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
.external-button {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.code-playground:hover .external-button {
|
||||||
|
display: inline-block;
|
||||||
|
position: absolute;
|
||||||
|
bottom: 2px;
|
||||||
|
right: 2px;
|
||||||
|
background-color: var(--primary);
|
||||||
|
color: white;
|
||||||
|
padding: 4px;
|
||||||
|
border-radius: 4px;
|
||||||
|
text-decoration: unset;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
||||||
|
<div class="code-playground">
|
||||||
|
{{ .Inner | markdownify }}
|
||||||
|
<a href="{{ .Params.link }}" target="_blank" rel="noopener" class="external-button">Try in playground</a>
|
||||||
|
</div>
|
Loading…
Reference in New Issue
Block a user