From 53f757e13e1f8732e3b867d125fd898d16371c02 Mon Sep 17 00:00:00 2001 From: f Date: Fri, 17 Sep 2021 15:29:02 -0300 Subject: [PATCH 1/6] Deprecar Turbolinks en favor de Turbo MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Funciona mejor con navegación por anchors también --- _packs/entry.js | 29 ++++++++--------------------- package.json | 1 + yarn.lock | 5 +++++ 3 files changed, 14 insertions(+), 21 deletions(-) diff --git a/_packs/entry.js b/_packs/entry.js index 44fd39e..9ba5f80 100644 --- a/_packs/entry.js +++ b/_packs/entry.js @@ -9,8 +9,14 @@ window.airbrake = new Notifier({ import 'core-js/stable' import 'regenerator-runtime/runtime' -const Turbolinks = require("turbolinks") -Turbolinks.start() +// Turbo acelera la navegación al no tener que recargar todo el JS y CSS +// de la página, con lo que se siente más rápida y "nativa". +// +// Cambiamos de turbolinks a turbo porque turbo soporta la función +// fetch(), que luego es interceptada por el SW para obtener las +// direcciones localmente. +import * as Turbo from "@hotwired/turbo" +Turbo.start() import { Application } from 'stimulus' import { definitionsFromContext } from "stimulus/webpack-helpers" @@ -19,23 +25,6 @@ const application = Application.start() const context = require.context("./controllers", true, /\.js$/) application.load(definitionsFromContext(context)) -// Prevenir que Turbolinks interfiera con la navegación por anchors -// https://github.com/turbolinks/turbolinks/issues/75#issuecomment-445325162 -document.addEventListener('turbolinks:click', event => { - const anchorElement = event.target - const isSamePageAnchor = ( - anchorElement.hash && - anchorElement.origin === window.location.origin && - anchorElement.pathname === window.location.pathname - ) - - if (!isSamePageAnchor) return - - Turbolinks.controller.pushHistoryWithLocationAndRestorationIdentifier(event.data.url, Turbolinks.uuid()) - - event.preventDefault() -}) - try { window.axe = require('axe-core/axe') } catch(e) {} @@ -45,8 +34,6 @@ if (window.axe) window.axe.configure({ locale: require('axe-core/locales/es.json // Prevenir que Turbolinks interfiera la navegación a un anchor al // recargar la página document.addEventListener('turbolinks:load', event => { - window.location.hash = window.location.hash - if (!window.axe) return window.axe.run().then(results => { diff --git a/package.json b/package.json index ae1140a..eb32fd3 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ "@babel/core": "^7.10.4", "@babel/plugin-proposal-class-properties": "^7.10.4", "@babel/preset-env": "^7.10.4", + "@hotwired/turbo": "^7.0.0-rc.4", "axe-core": "^4.1.2", "babel-loader": "^8.1.0", "core-js": "^3.6.5", diff --git a/yarn.lock b/yarn.lock index ca44c87..91a20bc 100644 --- a/yarn.lock +++ b/yarn.lock @@ -880,6 +880,11 @@ "@babel/helper-validator-identifier" "^7.14.0" to-fast-properties "^2.0.0" +"@hotwired/turbo@^7.0.0-rc.4": + version "7.0.0-rc.4" + resolved "https://registry.yarnpkg.com/@hotwired/turbo/-/turbo-7.0.0-rc.4.tgz#d3ab9555544534f5ec649613553e72ff6c7d7122" + integrity sha512-4qx+6O6mUN+cSN+ZLGCOGc+2MxNrs7cFbmnWD6LIfiHAQyuNiIuB87Y5IAtOo8xj16fOBd2CdU1WRJya4Wkw0A== + "@sindresorhus/is@^0.14.0": version "0.14.0" resolved "https://registry.yarnpkg.com/@sindresorhus/is/-/is-0.14.0.tgz#9fb3a3cf3132328151f353de4632e01e52102bea" From 07035125e6a34fea8a3a9ef2a81d036ec342273b Mon Sep 17 00:00:00 2001 From: f Date: Fri, 17 Sep 2021 15:41:25 -0300 Subject: [PATCH 2/6] Eliminar turbolinks --- package.json | 1 - yarn.lock | 5 ----- 2 files changed, 6 deletions(-) diff --git a/package.json b/package.json index eb32fd3..31bffef 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,6 @@ "sassdoc": "^2.7.3", "sassdoc-theme-herman": "^4.0.2", "stimulus": "^1.1.1", - "turbolinks": "^5.2.0", "webpack": "^4.43.0", "webpack-assets-manifest": "~4", "webpack-cli": "^3.3.12", diff --git a/yarn.lock b/yarn.lock index 91a20bc..5cceb8c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6319,11 +6319,6 @@ tty-browserify@0.0.0: resolved "https://registry.yarnpkg.com/tty-browserify/-/tty-browserify-0.0.0.tgz#a157ba402da24e9bf957f9aa69d524eed42901a6" integrity sha1-oVe6QC2iTpv5V/mqadUk7tQpAaY= -turbolinks@^5.2.0: - version "5.2.0" - resolved "https://registry.yarnpkg.com/turbolinks/-/turbolinks-5.2.0.tgz#e6877a55ea5c1cb3bb225f0a4ae303d6d32ff77c" - integrity sha512-pMiez3tyBo6uRHFNNZoYMmrES/IaGgMhQQM+VFF36keryjb5ms0XkVpmKHkfW/4Vy96qiGW3K9bz0tF5sK9bBw== - type-fest@^0.8.1: version "0.8.1" resolved "https://registry.yarnpkg.com/type-fest/-/type-fest-0.8.1.tgz#09e249ebde851d3b1e48d27c105444667f17b83d" From 7057324fc0ddbb26880f6ce948e70253a1c24fe6 Mon Sep 17 00:00:00 2001 From: f Date: Fri, 17 Sep 2021 15:41:37 -0300 Subject: [PATCH 3/6] Usar turbo:load --- _packs/entry.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/_packs/entry.js b/_packs/entry.js index 9ba5f80..8a4d710 100644 --- a/_packs/entry.js +++ b/_packs/entry.js @@ -31,9 +31,7 @@ try { if (window.axe) window.axe.configure({ locale: require('axe-core/locales/es.json') }) -// Prevenir que Turbolinks interfiera la navegación a un anchor al -// recargar la página -document.addEventListener('turbolinks:load', event => { +document.addEventListener('turbo:load', event => { if (!window.axe) return window.axe.run().then(results => { From 43cee04527d64c1151bf697d3058cbdeddd5fcd2 Mon Sep 17 00:00:00 2001 From: f Date: Fri, 17 Sep 2021 15:41:46 -0300 Subject: [PATCH 4/6] Eliminar estilo para la barra de progreso --- assets/css/styles.scss | 3 --- 1 file changed, 3 deletions(-) diff --git a/assets/css/styles.scss b/assets/css/styles.scss index 67d88db..a03496c 100644 --- a/assets/css/styles.scss +++ b/assets/css/styles.scss @@ -118,9 +118,6 @@ $label-margin-bottom: 0; @import "editor"; @import "menu"; -/// La barra de progreso de Turbolinks tiene el color primario -/// de la paleta, definido por Bootstrap o por nosotres. -.turbolinks-progress-bar { background-color: $primary; } /// La barra de progreso de Turbo tiene el color primario /// de la paleta, definido por Bootstrap o por nosotres. .turbo-progress-bar { background-color: $primary; } From 5be70267cb962a0e4f0bb4a9503eab1b31b4d9d6 Mon Sep 17 00:00:00 2001 From: f Date: Fri, 17 Sep 2021 15:42:57 -0300 Subject: [PATCH 5/6] Yapa: Eliminar JavaScript extra --- _packs/entry.js | 5 +++++ assets/js/script.js | 44 -------------------------------------------- 2 files changed, 5 insertions(+), 44 deletions(-) delete mode 100644 assets/js/script.js diff --git a/_packs/entry.js b/_packs/entry.js index 8a4d710..aac43aa 100644 --- a/_packs/entry.js +++ b/_packs/entry.js @@ -32,6 +32,11 @@ try { if (window.axe) window.axe.configure({ locale: require('axe-core/locales/es.json') }) document.addEventListener('turbo:load', event => { + document.querySelectorAll("a[href^='http://'],a[href^='https://'],a[href^='//']").forEach(a => { + a.rel = "noopener" + a.target = "_blank" + }) + if (!window.axe) return window.axe.run().then(results => { diff --git a/assets/js/script.js b/assets/js/script.js deleted file mode 100644 index bf5f470..0000000 --- a/assets/js/script.js +++ /dev/null @@ -1,44 +0,0 @@ ---- ---- - -const loadEvent = () => { - try { - if (Turbolinks) return 'turbolinks:load' - } catch { - return 'DOMContentLoaded' - } -} - -document.addEventListener(loadEvent(), () => { - document.querySelectorAll('.share').forEach(share => { - share.addEventListener('click', event => { - if (!Navigator.share) return; - - event.preventDefault(); - event.stopPropagation(); - - const title = document.querySelector('title').text; - - try { - const text = document.querySelector('meta[property="og:description"]').content; - } catch { - const text = ''; - } - - try { - const url = document.querySelector('link[rel=canonical]').href; - } catch { - const url = document.location.href; - } - - const data = { title: title, text: text, url: url }; - - if (Navigator.canShare(data)) Navigator.share(data).then(); - }); - }); - - document.querySelectorAll("a[href^='http://'],a[href^='https://'],a[href^='//']").forEach(a => { - a.rel = "noopener"; - a.target = "_blank"; - }); -}); From ea01cb0602f4b6be2f17f1ec1bfcf2e714570df4 Mon Sep 17 00:00:00 2001 From: f Date: Fri, 17 Sep 2021 20:28:39 -0300 Subject: [PATCH 6/6] =?UTF-8?q?Usar=20el=20caj=C3=B3n=20de=20compartir=20n?= =?UTF-8?q?ativo=20si=20est=C3=A1=20disponible?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- _includes/share_box.html | 15 +++++++++++++- _packs/controllers/share_controller.js | 27 ++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 _packs/controllers/share_controller.js diff --git a/_includes/share_box.html b/_includes/share_box.html index 3270986..7ecff0d 100644 --- a/_includes/share_box.html +++ b/_includes/share_box.html @@ -1,4 +1,17 @@ - +{%- assign title = include.title | escape -%} +{%- assign text = include.description | strip_html | escape -%} +{%- assign url = site.url | append: include.url | escape -%} + +