From 80f048de3a8bbaa369747907237ee104e660928a Mon Sep 17 00:00:00 2001 From: cupcakearmy Date: Sun, 29 Sep 2019 18:16:01 +0200 Subject: [PATCH] preloading --- .drone.yml | 38 +++++++++++++++++++------------------- package.json | 1 + src/js/index.js | 13 +++++++++++-- src/js/lazy.js | 6 +++--- src/js/lights.js | 6 +++--- src/js/swup.js | 11 +++++++++++ 6 files changed, 48 insertions(+), 27 deletions(-) create mode 100644 src/js/swup.js diff --git a/.drone.yml b/.drone.yml index 20bcb55..3e07ddd 100644 --- a/.drone.yml +++ b/.drone.yml @@ -8,22 +8,22 @@ steps: commands: - node -v - pnpm --shamefully-flatten i - - pnpm run build:prod -# -# -# - name: deploy -# image: cupcakearmy/drone-deploy -# pull: always -# environment: -# PLUGIN_KEY: -# from_secret: ssh_key -# settings: -# host: srv-0.nicco.io -# user: root -# port: 1312 -# target: /srv/web/blog -# sources: -# - ./liquet -# when: -# event: push -# branch: master \ No newline at end of file + - pnpm run build + + + - name: deploy + image: cupcakearmy/drone-deploy + pull: always + environment: + PLUGIN_KEY: + from_secret: ssh_key + settings: + host: srv-0.nicco.io + user: root + port: 1312 + target: /srv/web/blog + sources: + - ./liquet + when: + event: push + branch: master \ No newline at end of file diff --git a/package.json b/package.json index 9b408f6..2f9b326 100644 --- a/package.json +++ b/package.json @@ -5,6 +5,7 @@ "build": "parcel build --no-source-maps -d liquet/dist ./src/js/index.js ./src/styles/index.styl" }, "dependencies": { + "@swup/preload-plugin": "^1.0.3", "jquery": "^3.4.1", "swup": "^2.0.7" }, diff --git a/src/js/index.js b/src/js/index.js index cd5d784..1c0ade8 100644 --- a/src/js/index.js +++ b/src/js/index.js @@ -1,2 +1,11 @@ -import './lights' -import './lazy' \ No newline at end of file +import lights from './lights' +import lazy from './lazy' +import swup from './swup' + +document.addEventListener('DOMContentLoaded', () => { + lights() + lazy() + swup(()=> { + lazy() + }) +}) \ No newline at end of file diff --git a/src/js/lazy.js b/src/js/lazy.js index 76133c6..78b5713 100644 --- a/src/js/lazy.js +++ b/src/js/lazy.js @@ -1,6 +1,6 @@ -import jQuery from 'jquery' +import $ from 'jquery' -jQuery(($) => { +export default () => { const bottomOffset = 300 const app = document.getElementById('app') let loading = false @@ -35,4 +35,4 @@ jQuery(($) => { // Check initial page if they need loading load.bind(app)() -}) \ No newline at end of file +} \ No newline at end of file diff --git a/src/js/lights.js b/src/js/lights.js index c9c24cf..f244250 100644 --- a/src/js/lights.js +++ b/src/js/lights.js @@ -1,4 +1,4 @@ -;((window) => { +export default () => { // Lights const key = 'nicco.io:blog:lights' const CSS = 'body, .wp-block-image img, .thumbnail img {filter: invert(1);} ' @@ -22,9 +22,9 @@ window.toggleLights = () => isDark() ? on() : off() // Focus scrolling - document.addEventListener('DOMContentLoaded', ()=> { + document.addEventListener('DOMContentLoaded', () => { const toFocus = document.querySelector('[data-focusme]') toFocus.tabIndex = '1' toFocus.focus({preventScroll: true}) }) -})(window) \ No newline at end of file +} \ No newline at end of file diff --git a/src/js/swup.js b/src/js/swup.js new file mode 100644 index 0000000..85e30e9 --- /dev/null +++ b/src/js/swup.js @@ -0,0 +1,11 @@ +import Swup from 'swup' +import SwupPreloadPlugin from '@swup/preload-plugin'; + +export default (fn) => { + const swup = new Swup({ + plugins: [new SwupPreloadPlugin()], + containers: ['#app'] + }) + + swup.on('contentReplaced', fn) +}