Merge branch 'templates-en-env' into 'master'
Templates en env See merge request sutty/jekyll/sutty-base-jekyll-theme!20
This commit is contained in:
commit
fd3660ed62
6 changed files with 46 additions and 30 deletions
|
@ -24,7 +24,7 @@
|
||||||
si no existe.
|
si no existe.
|
||||||
{% endcomment %}
|
{% endcomment %}
|
||||||
<link rel="preload" as="script" type="text/javascript" href="env.js" />
|
<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 %}
|
{% include_cached pack.html %}
|
||||||
|
|
||||||
{% comment %}
|
{% comment %}
|
||||||
|
|
|
@ -15,13 +15,9 @@ export default class extends Controller {
|
||||||
* nothing if the template isn't found.
|
* nothing if the template isn't found.
|
||||||
*/
|
*/
|
||||||
async render (name, data = {}) {
|
async render (name, data = {}) {
|
||||||
const response = await fetch(this.template(name))
|
|
||||||
|
|
||||||
if (!response.ok) return
|
|
||||||
|
|
||||||
data.site = window.site
|
data.site = window.site
|
||||||
|
|
||||||
const template = await response.text()
|
const template = window.templates.alert
|
||||||
const html = await this.engine.parseAndRender(template, data)
|
const html = await this.engine.parseAndRender(template, data)
|
||||||
|
|
||||||
this.element.innerHTML = html
|
this.element.innerHTML = html
|
||||||
|
|
|
@ -48,8 +48,7 @@ export default class extends Controller {
|
||||||
const main = document.querySelector('main')
|
const main = document.querySelector('main')
|
||||||
const results = window.index.search(q).map(r => window.data.find(a => a.id == r.ref))
|
const results = window.index.search(q).map(r => window.data.find(a => a.id == r.ref))
|
||||||
const site = window.site
|
const site = window.site
|
||||||
const request = await fetch('assets/templates/results.html')
|
const template = window.templates.results
|
||||||
const template = await request.text()
|
|
||||||
const html = await this.engine.parseAndRender(template, { q, site, results })
|
const html = await this.engine.parseAndRender(template, { q, site, results })
|
||||||
const title = `${site.i18n.search.title} - ${q}`
|
const title = `${site.i18n.search.title} - ${q}`
|
||||||
const query = new URLSearchParams({ q })
|
const query = new URLSearchParams({ q })
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
{%- raw -%}
|
||||||
<div class="alert alert-{{ type }} alert-dismissible" role="alert">
|
<div class="alert alert-{{ type }} alert-dismissible" role="alert">
|
||||||
{{ content }}
|
{{ content }}
|
||||||
|
|
||||||
|
@ -5,3 +6,4 @@
|
||||||
<span aria-hidden="true">×</span>
|
<span aria-hidden="true">×</span>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
{%- endraw -%}
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
{%- raw -%}
|
||||||
<section class="row no-gutters justify-content-center">
|
<section class="row no-gutters justify-content-center">
|
||||||
<div class="col-10">
|
<div class="col-10">
|
||||||
{% for item in results %}
|
{% for item in results %}
|
||||||
|
@ -15,3 +16,4 @@
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
{%- endraw -%}
|
||||||
|
|
17
env.js
17
env.js
|
@ -10,3 +10,20 @@ window.env = {
|
||||||
window.site = {
|
window.site = {
|
||||||
"i18n": {{ site.i18n | jsonify }}
|
"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 }},
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue