Merge branch 'master' into tienda

This commit is contained in:
f 2021-10-28 09:44:36 -03:00
commit eea2dc801b
8 changed files with 64 additions and 55 deletions

View file

@ -24,7 +24,7 @@
si no existe.
{% endcomment %}
<link rel="preload" as="script" type="text/javascript" href="env.js" />
<script type="text/javascript" src="env.js"></script>
<script type="text/javascript" src="env.js?{{ site.time | date: '%s' }}"></script>
{% include_cached pack.html %}
{% comment %}

View file

@ -15,13 +15,9 @@ export default class extends Controller {
* nothing if the template isn't found.
*/
async render (name, data = {}) {
const response = await fetch(this.template(name))
data.site = window.site
if (!response.ok) return
data.site = await this.site()
const template = await response.text()
const template = window.templates.alert
const html = await this.engine.parseAndRender(template, data)
this.element.innerHTML = html
@ -63,18 +59,4 @@ export default class extends Controller {
return window.liquid
}
/*
* Site config (actually just translation strings)
*
* @return [Object]
*/
async site () {
if (!window.site) {
const data = await fetch('assets/data/site.json')
window.site = await data.json()
}
return window.site
}
}

View file

@ -47,9 +47,8 @@ export default class extends Controller {
const main = document.querySelector('main')
const results = window.index.search(q).map(r => window.data.find(a => a.id == r.ref))
const site = await this.site()
const request = await fetch('assets/templates/results.html')
const template = await request.text()
const site = window.site
const template = window.templates.results
const html = await this.engine.parseAndRender(template, { q, site, results })
const title = `${site.i18n.search.title} - ${q}`
const query = new URLSearchParams({ q })
@ -98,13 +97,4 @@ export default class extends Controller {
return window.liquid
}
async site () {
if (!window.site) {
const data = await fetch('assets/data/site.json')
window.site = await data.json()
}
return window.site
}
}

11
_sass/content.scss Normal file
View file

@ -0,0 +1,11 @@
/// Todos los elementos dentro de .content tienen margen inferior, salvo
/// el último, para no modificar el padding y margin del contenedor.
.content {
& > * {
margin-bottom: 1rem;
&:last-child {
margin-bottom: 0;
}
}
}

View file

@ -132,6 +132,7 @@ $label-margin-bottom: 0;
@import "snap";
@import "editor";
@import "menu";
@import "content";
/// La barra de progreso de Turbo tiene el color primario
/// de la paleta, definido por Bootstrap o por nosotres.

View file

@ -1,7 +1,9 @@
<div class="alert alert-{{ type }} alert-dismissible" role="alert">
{%- raw -%}
<div class="alert alert-{{ type }} alert-dismissible" role="alert">
{{ content }}
<button data-action="notification#hide" type="button" class="close" aria-label="{{ site.i18n.close }}">
<span aria-hidden="true">&times;</span>
</button>
</div>
</div>
{%- endraw -%}

View file

@ -1,4 +1,5 @@
<section class="row no-gutters justify-content-center">
{%- raw -%}
<section class="row no-gutters justify-content-center">
<div class="col-10">
{% for item in results %}
<article id="{{ item.slug }}">
@ -14,4 +15,5 @@
</article>
{% endfor %}
</div>
</section>
</section>
{%- endraw -%}

21
env.js
View file

@ -7,3 +7,24 @@ window.env = {
JEKYLL_ENV: '{{ site.env.JEKYLL_ENV }}',
SPREE_URL: '{{ site.env.SPREE_URL }}'
}
window.site = {
"i18n": {{ site.i18n | jsonify }}
}
{%- comment -%}
Para agregar plantillas que se procesan con JS, las agregamos en
Liquid dentro de assets/templates/ y luego las importamos acá, de forma
que estén disponibles para JS sin tener que descargarlas.
Es importante que la plantilla esté envuelta por el tag `{% raw %}`,
para que no sea procesado en el momento de generar env.js, sino en el
navegador.
{%- endcomment -%}
{%- capture alert %}{% include_relative assets/templates/alert.html %}{% endcapture -%}
{%- capture results %}{% include_relative assets/templates/results.html %}{% endcapture -%}
window.templates = {
"alert": {{ alert | jsonify }},
"results": {{ results | jsonify }},
}