Skip to content

Commit fdaac22

Browse files
committed
Búsqueda
1 parent 5bbab5b commit fdaac22

File tree

9 files changed

+115
-15
lines changed

9 files changed

+115
-15
lines changed

content/search/_index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
---
2+
---

layouts/partials/search-form.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<form class="pa4 black-80"
2+
action='{{ with .GetPage "/search" }}{{.Permalink}}{{end}}' method="get">
3+
<fieldset class="cf bn ma0 pa0">
4+
<div class="cf">
5+
<label for="search-input" class="f6 b db mb2">Búsqueda</label>
6+
<input type="text" class="f6 f5-l input-reset bn fl black-80 bg-white pa3 lh-solid w-100 w-75-m w-80-l br2-ns br--left-ns" id="search-input" name="query" placeholder="Palabras a buscar">
7+
<input type="submit" class="f6 f5-l button-reset fl pv3 tc bn bg-animate bg-black-70 hover-bg-black white pointer w-100 w-25-m w-20-l br2-ns br--right-ns" value="Buscar">
8+
</div>
9+
</fieldset>
10+
</form>

layouts/partials/search-index.html

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<script>
2+
window.store = {
3+
{{ range where .Site.Pages "Section" "posts" }}
4+
"{{ .Permalink }}": {
5+
"title": "{{ .Title }}",
6+
"tags": [{{ range .Params.Tags }}"{{ . }}",{{ end }}],
7+
"content": {{ .Content | plainify }},
8+
"url": "{{ .Permalink }}"
9+
},
10+
{{ end }}
11+
}
12+
</script>
13+
<script src="https://cdnjs.cloudflare.com/ajax/libs/lunr.js/2.3.9/lunr.min.js" integrity="sha512-4xUl/d6D6THrAnXAwGajXkoWaeMNwEKK4iNfq5DotEbLPAfk6FSxSP3ydNxqDgCw1c/0Z1Jg6L8h2j+++9BZmg==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
14+
<script src="/js/search.js"></script>

layouts/search/list.html

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{{ define "header" }}{{ partial "page-header.html" . }}{{ end }}
2+
{{ define "main" }}
3+
<article class="flex-l flex-wrap justify-between mw8 center ph3">
4+
<header class="mt4 w-100">
5+
<h1 class="f1">Búsqueda</h1>
6+
</header>
7+
<div class="nested-copy-line-height lh-copy f4 nested-links nested-img {{ $.Param "text_color" | default "mid-gray" }}">
8+
{{ partial "search-form.html" . }}
9+
<ul id="results">
10+
<li>
11+
Escribe palabras clave arriba para buscar este sitio.
12+
</li>
13+
</ul>
14+
</div>
15+
</article>
16+
{{ partial "search-index.html" . }}
17+
{{ end }}

static/css/styles.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,9 @@ header.bg-top h2 {
2525
color: white;
2626
opacity: 0.8;
2727
}
28+
29+
.sticky {
30+
position: -webkit-sticky;
31+
position: sticky;
32+
top: 0;
33+
}

static/js/search.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
const idx = lunr(function () {
2+
this.ref("id");
3+
this.field("title", { boost: 15 });
4+
this.field("tags");
5+
this.field("content", { boost: 10 });
6+
7+
for (const key in window.store) {
8+
this.add({
9+
id: key,
10+
title: window.store[key].title,
11+
tags: window.store[key].category,
12+
content: window.store[key].content,
13+
});
14+
}
15+
});
16+
17+
(() => {
18+
const params = new URLSearchParams(window.location.search);
19+
const query = params.get("query");
20+
if (!query) {
21+
return;
22+
}
23+
const results = idx.search(query);
24+
const searchResults = document.getElementById("results");
25+
26+
if (results.length) {
27+
let resultList = "";
28+
for (const n in results) {
29+
const item = store[results[n].ref];
30+
resultList +=
31+
'<li><p><a href="' + item.url + '">' + item.title + "</a></p>";
32+
resultList += "<p>" + item.content.substring(0, 150) + "...</p></li>";
33+
}
34+
searchResults.innerHTML = resultList;
35+
} else {
36+
searchResults.innerHTML = "No se encontraron resultados.";
37+
}
38+
})();

themes/omegaup/layouts/_default/single.html

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,21 @@
1616
</aside>
1717
{{ partial "social-share.html" . }}
1818
<p class="tracked p0 mb0">
19-
{{/* Hugo uses Go's date formatting is set by example. Here are two formats */}}
20-
{{ if not .Date.IsZero }}
21-
<time class="f6 dib tracked" {{ printf `datetime="%s"` (.Date.Format "2006-01-02T15:04:05Z07:00") | safeHTMLAttr }}>
22-
{{- .Date.Format (default "January 2, 2006" .Site.Params.date_format) -}}
23-
</time>
24-
{{end}}
25-
{{ with .Params.author | default .Site.Params.author }}
26-
Por <strong>
27-
{{ if reflect.IsSlice . }}
28-
{{ delimit . ", " | markdownify }}
29-
{{else}}
30-
{{ . | markdownify }}
31-
{{ end }}
32-
</strong>
33-
{{ end }}
19+
{{/* Hugo uses Go's date formatting is set by example. Here are two formats */}}
20+
{{ if not .Date.IsZero }}
21+
<time class="f6 dib tracked" {{ printf `datetime="%s"` (.Date.Format "2006-01-02T15:04:05Z07:00") | safeHTMLAttr }}>
22+
{{- .Date.Format (default "January 2, 2006" .Site.Params.date_format) -}}
23+
</time>
24+
{{end}}
25+
{{ with .Params.author | default .Site.Params.author }}
26+
Por <strong>
27+
{{ if reflect.IsSlice . }}
28+
{{ delimit . ", " | markdownify }}
29+
{{else}}
30+
{{ . | markdownify }}
31+
{{ end }}
32+
</strong>
33+
{{ end }}
3434
</p>
3535
<h1 class="f2 pv2 mv1">
3636
{{- .Title -}}

themes/omegaup/layouts/partials/page-header.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,10 @@
1414
</div>
1515
</header>
1616
{{ end }}
17+
<header class="bg-black-90 sticky w-100 ph3 pv3 pv4-ns ph4-m ph5-l">
18+
<nav class="f6 fw6 ttu tracked">
19+
<a class="link dim white dib mr3" href="{{ relURL "/" }}" title="Inicio">Inicio</a>
20+
<a class="link dim white dib mr3" href="{{ relURL "/search/" }}" title="Búsqueda">Búsqueda</a>
21+
<a class="link dim white dib" href="https://omegaup.org/" title="Acerca de">Acerca de</a>
22+
</nav>
23+
</header>

themes/omegaup/layouts/partials/site-header.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,9 @@ <h2 class="fw1 f5 f3-l white-80 measure-wide-l center lh-copy mt3 mb4">
3333
</div>
3434
</header>
3535
{{ end }}
36+
<header class="bg-black-90 sticky w-100 ph3 pv3 pv4-ns ph4-m ph5-l">
37+
<nav class="f6 fw6 ttu tracked w-70-ns center">
38+
<a class="link dim white dib mr3" href="{{ relURL "/search/" }}" title="Búsqueda">Búsqueda</a>
39+
<a class="link dim white dib" href="https://omegaup.org/" title="Acerca de">Acerca de</a>
40+
</nav>
41+
</header>

0 commit comments

Comments
 (0)