From 3506e0a0184c543e215caba39d7d6bbc62a618cd Mon Sep 17 00:00:00 2001 From: Matthew Swezey Date: Thu, 17 Sep 2020 17:55:03 -0500 Subject: [PATCH 1/9] =?UTF-8?q?lint=20fixes=20and=20link=20updates=20?= =?UTF-8?q?=E2=9C=A8=F0=9F=93=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .DS_Store | Bin 0 -> 8196 bytes .gitignore | 1 + .nuxt/App.js | 203 + .nuxt/client.js | 628 ++ .nuxt/components/nuxt-child.js | 122 + .nuxt/components/nuxt-error.vue | 96 + .nuxt/components/nuxt-link.client.js | 98 + .nuxt/components/nuxt-link.server.js | 16 + .nuxt/components/nuxt-loading.vue | 177 + .nuxt/components/nuxt.js | 101 + .nuxt/empty.js | 1 + .nuxt/index.js | 216 + .nuxt/jsonp.js | 80 + .nuxt/loading.html | 108 + .nuxt/middleware.js | 3 + .nuxt/mixins/fetch.client.js | 90 + .nuxt/mixins/fetch.server.js | 51 + .nuxt/nuxt-svg-sprite.js | 107 + .nuxt/router.js | 40 + .nuxt/router.scrollBehavior.js | 76 + .nuxt/routes.json | 16 + .nuxt/server.js | 268 + .nuxt/utils.js | 634 ++ .nuxt/views/app.template.html | 9 + .nuxt/views/error.html | 23 + components/footer.vue | 2 +- data/index/data.json.js | 18 +- layouts/default.vue | 12 +- package.json | 4 +- pages/index.vue | 22 +- pages/news/:id.vue | 4 +- yarn.lock | 9986 ++++++++++++++++++++++++++ 32 files changed, 13179 insertions(+), 33 deletions(-) create mode 100644 .DS_Store create mode 100644 .nuxt/App.js create mode 100644 .nuxt/client.js create mode 100644 .nuxt/components/nuxt-child.js create mode 100644 .nuxt/components/nuxt-error.vue create mode 100644 .nuxt/components/nuxt-link.client.js create mode 100644 .nuxt/components/nuxt-link.server.js create mode 100644 .nuxt/components/nuxt-loading.vue create mode 100644 .nuxt/components/nuxt.js create mode 100644 .nuxt/empty.js create mode 100644 .nuxt/index.js create mode 100644 .nuxt/jsonp.js create mode 100644 .nuxt/loading.html create mode 100644 .nuxt/middleware.js create mode 100644 .nuxt/mixins/fetch.client.js create mode 100644 .nuxt/mixins/fetch.server.js create mode 100644 .nuxt/nuxt-svg-sprite.js create mode 100644 .nuxt/router.js create mode 100644 .nuxt/router.scrollBehavior.js create mode 100644 .nuxt/routes.json create mode 100644 .nuxt/server.js create mode 100644 .nuxt/utils.js create mode 100644 .nuxt/views/app.template.html create mode 100644 .nuxt/views/error.html create mode 100644 yarn.lock diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..91d286f3c49c7986a16542cd8332801548a66120 GIT binary patch literal 8196 zcmeHM-HsA582!4--{`IqW3ubr+?aTQgw;gc7!ySHVlPaL7`;%#4h*vBFhgLFT@k~L z?_l%^d=+272k`;)d~GH3118=WH@2ibo%TEZIbWI5LPVlIarcOJiKu|cSUitpMc{gl zsj#6-E&&DjL?Mk2y`aTNa$)-)~@ zDmn>8C!u>5`h+56@8H?eoJ38bNsR(VfwTgAcF&PRV|==a^E-c)?jT7_#WL$Sf&-m$~6CSs9{&5g^%e>Qm((g`N#mn~tKXm$jcO=Pu zw+oZ!Py4#Er7|zsvud?cvTyC*n9r@k&egrU zhew0cx3hQi_n)MWB=n1nE~@8c`WZP^Oe*oFIr6>0@1czCx9Ju1VGsE95*9rw%Mv^% zH2V(gsNeGB!3U>cPF8q~z5Fre(Bw~HPRk>{+$|8URLs$kr*AXcTtEak%y&+ z@%5mGpR$GqF>8w+(E;6~20Z|lp@W;40oHtsk>mA_(T8Zild#2XW42jo8>D?9;O&^D z1y8fje2l?^FQ8DoZ8^`A$UGrzD)5T45gBV57YezE%jGT%H2XgbVuDfN3@Naw#=6Vr z|AY1S|7U1MW~fF1qrjgkATo_+qYjqb)mN~2m$wm*5IL~jLZPG}iTx13^YRZv1eC5G4raB0$Pu5~ILhRp2M_eJSh! literal 0 HcmV?d00001 diff --git a/.gitignore b/.gitignore index 7a1537b..2fd83a6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ .idea node_modules +dist diff --git a/.nuxt/App.js b/.nuxt/App.js new file mode 100644 index 0000000..ff5149e --- /dev/null +++ b/.nuxt/App.js @@ -0,0 +1,203 @@ +import Vue from 'vue' + +import { getMatchedComponentsInstances, getChildrenComponentInstancesUsingFetch, promisify, globalHandleError, urlJoin, sanitizeComponent } from './utils' + +import NuxtLoading from './components/nuxt-loading.vue' + +import '../assets/sass/styles.scss' + +import _6f6c098b from '../layouts/default.vue' + +const layouts = { "_default": sanitizeComponent(_6f6c098b) } + +export default { + render (h, props) { + const loadingEl = h('NuxtLoading', { ref: 'loading' }) + + const layoutEl = h(this.layout || 'nuxt') + const templateEl = h('div', { + domProps: { + id: '__layout' + }, + key: this.layoutName + }, [layoutEl]) + + const transitionEl = h('transition', { + props: { + name: 'layout', + mode: 'out-in' + }, + on: { + beforeEnter (el) { + // Ensure to trigger scroll event after calling scrollBehavior + window.$nuxt.$nextTick(() => { + window.$nuxt.$emit('triggerScroll') + }) + } + } + }, [templateEl]) + + return h('div', { + domProps: { + id: '__nuxt' + } + }, [ + loadingEl, + + transitionEl + ]) + }, + + data: () => ({ + isOnline: true, + + layout: null, + layoutName: '', + + nbFetching: 0 + }), + + beforeCreate () { + Vue.util.defineReactive(this, 'nuxt', this.$options.nuxt) + }, + created () { + // Add this.$nuxt in child instances + Vue.prototype.$nuxt = this + if (process.client) { + // add to window so we can listen when ready + window.$nuxt = this + + this.refreshOnlineStatus() + // Setup the listeners + window.addEventListener('online', this.refreshOnlineStatus) + window.addEventListener('offline', this.refreshOnlineStatus) + } + // Add $nuxt.error() + this.error = this.nuxt.error + // Add $nuxt.context + this.context = this.$options.context + }, + + async mounted () { + this.$loading = this.$refs.loading + }, + + watch: { + 'nuxt.err': 'errorChanged' + }, + + computed: { + isOffline () { + return !this.isOnline + }, + + isFetching () { + return this.nbFetching > 0 + }, + + isPreview () { + return Boolean(this.$options.previewData) + }, + }, + + methods: { + refreshOnlineStatus () { + if (process.client) { + if (typeof window.navigator.onLine === 'undefined') { + // If the browser doesn't support connection status reports + // assume that we are online because most apps' only react + // when they now that the connection has been interrupted + this.isOnline = true + } else { + this.isOnline = window.navigator.onLine + } + } + }, + + async refresh () { + const pages = getMatchedComponentsInstances(this.$route) + + if (!pages.length) { + return + } + this.$loading.start() + + const promises = pages.map((page) => { + const p = [] + + // Old fetch + if (page.$options.fetch && page.$options.fetch.length) { + p.push(promisify(page.$options.fetch, this.context)) + } + if (page.$fetch) { + p.push(page.$fetch()) + } else { + // Get all component instance to call $fetch + for (const component of getChildrenComponentInstancesUsingFetch(page.$vnode.componentInstance)) { + p.push(component.$fetch()) + } + } + + if (page.$options.asyncData) { + p.push( + promisify(page.$options.asyncData, this.context) + .then((newData) => { + for (const key in newData) { + Vue.set(page.$data, key, newData[key]) + } + }) + ) + } + + return Promise.all(p) + }) + try { + await Promise.all(promises) + } catch (error) { + this.$loading.fail(error) + globalHandleError(error) + this.error(error) + } + this.$loading.finish() + }, + errorChanged () { + if (this.nuxt.err) { + if (this.$loading) { + if (this.$loading.fail) { + this.$loading.fail(this.nuxt.err) + } + if (this.$loading.finish) { + this.$loading.finish() + } + } + + let errorLayout = (NuxtError.options || NuxtError).layout; + + if (typeof errorLayout === 'function') { + errorLayout = errorLayout(this.context) + } + + this.setLayout(errorLayout) + } + }, + + setLayout (layout) { + if (!layout || !layouts['_' + layout]) { + layout = 'default' + } + this.layoutName = layout + this.layout = layouts['_' + layout] + return this.layout + }, + loadLayout (layout) { + if (!layout || !layouts['_' + layout]) { + layout = 'default' + } + return Promise.resolve(layouts['_' + layout]) + }, + }, + + components: { + NuxtLoading + } +} diff --git a/.nuxt/client.js b/.nuxt/client.js new file mode 100644 index 0000000..1aab239 --- /dev/null +++ b/.nuxt/client.js @@ -0,0 +1,628 @@ +import Vue from 'vue' +import fetch from 'unfetch' +import middleware from './middleware.js' +import { + applyAsyncData, + promisify, + middlewareSeries, + sanitizeComponent, + resolveRouteComponents, + getMatchedComponents, + getMatchedComponentsInstances, + flatMapComponents, + setContext, + getLocation, + compile, + getQueryDiff, + globalHandleError, + isSamePath +} from './utils.js' +import { createApp, NuxtError } from './index.js' +import fetchMixin from './mixins/fetch.client' +import NuxtLink from './components/nuxt-link.client.js' // should be included after ./index.js + +// Fetch mixin +if (!Vue.__nuxt__fetch__mixin__) { + Vue.mixin(fetchMixin) + Vue.__nuxt__fetch__mixin__ = true +} + +// Component: +Vue.component(NuxtLink.name, NuxtLink) +Vue.component('NLink', NuxtLink) + +if (!global.fetch) { global.fetch = fetch } + +// Global shared references +let _lastPaths = [] +let app +let router + +// Try to rehydrate SSR data from window +const NUXT = window.__NUXT__ || {} + +Object.assign(Vue.config, {"silent":true,"performance":false}) + +const errorHandler = Vue.config.errorHandler || console.error + +// Create and mount App +createApp(null, NUXT.config).then(mountApp).catch(errorHandler) + +function componentOption (component, key, ...args) { + if (!component || !component.options || !component.options[key]) { + return {} + } + const option = component.options[key] + if (typeof option === 'function') { + return option(...args) + } + return option +} + +function mapTransitions (toComponents, to, from) { + const componentTransitions = (component) => { + const transition = componentOption(component, 'transition', to, from) || {} + return (typeof transition === 'string' ? { name: transition } : transition) + } + + const fromComponents = from ? getMatchedComponents(from) : [] + const maxDepth = Math.max(toComponents.length, fromComponents.length) + + const mergedTransitions = [] + for (let i=0; i typeof toTransitions[key] !== 'undefined' && !key.toLowerCase().includes('leave')) + .forEach((key) => { transitions[key] = toTransitions[key] }) + + mergedTransitions.push(transitions) + } + return mergedTransitions +} + +async function loadAsyncComponents (to, from, next) { + // Check if route changed (this._routeChanged), only if the page is not an error (for validate()) + this._routeChanged = Boolean(app.nuxt.err) || from.name !== to.name + this._paramChanged = !this._routeChanged && from.path !== to.path + this._queryChanged = !this._paramChanged && from.fullPath !== to.fullPath + this._diffQuery = (this._queryChanged ? getQueryDiff(to.query, from.query) : []) + + if ((this._routeChanged || this._paramChanged) && this.$loading.start && !this.$loading.manual) { + this.$loading.start() + } + + try { + if (this._queryChanged) { + const Components = await resolveRouteComponents( + to, + (Component, instance) => ({ Component, instance }) + ) + // Add a marker on each component that it needs to refresh or not + const startLoader = Components.some(({ Component, instance }) => { + const watchQuery = Component.options.watchQuery + if (watchQuery === true) { + return true + } + if (Array.isArray(watchQuery)) { + return watchQuery.some(key => this._diffQuery[key]) + } + if (typeof watchQuery === 'function') { + return watchQuery.apply(instance, [to.query, from.query]) + } + return false + }) + + if (startLoader && this.$loading.start && !this.$loading.manual) { + this.$loading.start() + } + } + // Call next() + next() + } catch (error) { + const err = error || {} + const statusCode = err.statusCode || err.status || (err.response && err.response.status) || 500 + const message = err.message || '' + + // Handle chunk loading errors + // This may be due to a new deployment or a network problem + if (/^Loading( CSS)? chunk (\d)+ failed\./.test(message)) { + window.location.reload(true /* skip cache */) + return // prevent error page blinking for user + } + + this.error({ statusCode, message }) + this.$nuxt.$emit('routeChanged', to, from, err) + next() + } +} + +function applySSRData (Component, ssrData) { + if (NUXT.serverRendered && ssrData) { + applyAsyncData(Component, ssrData) + } + + Component._Ctor = Component + return Component +} + +// Get matched components +function resolveComponents (router) { + const path = getLocation(router.options.base, router.options.mode) + + return flatMapComponents(router.match(path), async (Component, _, match, key, index) => { + // If component is not resolved yet, resolve it + if (typeof Component === 'function' && !Component.options) { + Component = await Component() + } + // Sanitize it and save it + const _Component = applySSRData(sanitizeComponent(Component), NUXT.data ? NUXT.data[index] : null) + match.components[key] = _Component + return _Component + }) +} + +function callMiddleware (Components, context, layout) { + let midd = [] + let unknownMiddleware = false + + // If layout is undefined, only call global middleware + if (typeof layout !== 'undefined') { + midd = [] // Exclude global middleware if layout defined (already called before) + layout = sanitizeComponent(layout) + if (layout.options.middleware) { + midd = midd.concat(layout.options.middleware) + } + Components.forEach((Component) => { + if (Component.options.middleware) { + midd = midd.concat(Component.options.middleware) + } + }) + } + + midd = midd.map((name) => { + if (typeof name === 'function') { + return name + } + if (typeof middleware[name] !== 'function') { + unknownMiddleware = true + this.error({ statusCode: 500, message: 'Unknown middleware ' + name }) + } + return middleware[name] + }) + + if (unknownMiddleware) { + return + } + return middlewareSeries(midd, context) +} + +async function render (to, from, next) { + if (this._routeChanged === false && this._paramChanged === false && this._queryChanged === false) { + return next() + } + // Handle first render on SPA mode + let spaFallback = false + if (to === from) { + _lastPaths = [] + spaFallback = true + } else { + const fromMatches = [] + _lastPaths = getMatchedComponents(from, fromMatches).map((Component, i) => { + return compile(from.matched[fromMatches[i]].path)(from.params) + }) + } + + // nextCalled is true when redirected + let nextCalled = false + const _next = (path) => { + if (from.path === path.path && this.$loading.finish) { + this.$loading.finish() + } + + if (from.path !== path.path && this.$loading.pause) { + this.$loading.pause() + } + + if (nextCalled) { + return + } + + nextCalled = true + next(path) + } + + // Update context + await setContext(app, { + route: to, + from, + next: _next.bind(this) + }) + this._dateLastError = app.nuxt.dateErr + this._hadError = Boolean(app.nuxt.err) + + // Get route's matched components + const matches = [] + const Components = getMatchedComponents(to, matches) + + // If no Components matched, generate 404 + if (!Components.length) { + // Default layout + await callMiddleware.call(this, Components, app.context) + if (nextCalled) { + return + } + + // Load layout for error page + const errorLayout = (NuxtError.options || NuxtError).layout + const layout = await this.loadLayout( + typeof errorLayout === 'function' + ? errorLayout.call(NuxtError, app.context) + : errorLayout + ) + + await callMiddleware.call(this, Components, app.context, layout) + if (nextCalled) { + return + } + + // Show error page + app.context.error({ statusCode: 404, message: 'This page could not be found' }) + return next() + } + + // Update ._data and other properties if hot reloaded + Components.forEach((Component) => { + if (Component._Ctor && Component._Ctor.options) { + Component.options.asyncData = Component._Ctor.options.asyncData + Component.options.fetch = Component._Ctor.options.fetch + } + }) + + // Apply transitions + this.setTransitions(mapTransitions(Components, to, from)) + + try { + // Call middleware + await callMiddleware.call(this, Components, app.context) + if (nextCalled) { + return + } + if (app.context._errored) { + return next() + } + + // Set layout + let layout = Components[0].options.layout + if (typeof layout === 'function') { + layout = layout(app.context) + } + layout = await this.loadLayout(layout) + + // Call middleware for layout + await callMiddleware.call(this, Components, app.context, layout) + if (nextCalled) { + return + } + if (app.context._errored) { + return next() + } + + // Call .validate() + let isValid = true + try { + for (const Component of Components) { + if (typeof Component.options.validate !== 'function') { + continue + } + + isValid = await Component.options.validate(app.context) + + if (!isValid) { + break + } + } + } catch (validationError) { + // ...If .validate() threw an error + this.error({ + statusCode: validationError.statusCode || '500', + message: validationError.message + }) + return next() + } + + // ...If .validate() returned false + if (!isValid) { + this.error({ statusCode: 404, message: 'This page could not be found' }) + return next() + } + + let instances + // Call asyncData & fetch hooks on components matched by the route. + await Promise.all(Components.map(async (Component, i) => { + // Check if only children route changed + Component._path = compile(to.matched[matches[i]].path)(to.params) + Component._dataRefresh = false + const childPathChanged = Component._path !== _lastPaths[i] + // Refresh component (call asyncData & fetch) when: + // Route path changed part includes current component + // Or route param changed part includes current component and watchParam is not `false` + // Or route query is changed and watchQuery returns `true` + if (this._routeChanged && childPathChanged) { + Component._dataRefresh = true + } else if (this._paramChanged && childPathChanged) { + const watchParam = Component.options.watchParam + Component._dataRefresh = watchParam !== false + } else if (this._queryChanged) { + const watchQuery = Component.options.watchQuery + if (watchQuery === true) { + Component._dataRefresh = true + } else if (Array.isArray(watchQuery)) { + Component._dataRefresh = watchQuery.some(key => this._diffQuery[key]) + } else if (typeof watchQuery === 'function') { + if (!instances) { + instances = getMatchedComponentsInstances(to) + } + Component._dataRefresh = watchQuery.apply(instances[i], [to.query, from.query]) + } + } + if (!this._hadError && this._isMounted && !Component._dataRefresh) { + return + } + + const promises = [] + + const hasAsyncData = ( + Component.options.asyncData && + typeof Component.options.asyncData === 'function' + ) + + const hasFetch = Boolean(Component.options.fetch) && Component.options.fetch.length + + const loadingIncrease = (hasAsyncData && hasFetch) ? 30 : 45 + + // Call asyncData(context) + if (hasAsyncData) { + const promise = promisify(Component.options.asyncData, app.context) + + promise.then((asyncDataResult) => { + applyAsyncData(Component, asyncDataResult) + + if (this.$loading.increase) { + this.$loading.increase(loadingIncrease) + } + }) + promises.push(promise) + } + + // Check disabled page loading + this.$loading.manual = Component.options.loading === false + + // Call fetch(context) + if (hasFetch) { + let p = Component.options.fetch(app.context) + if (!p || (!(p instanceof Promise) && (typeof p.then !== 'function'))) { + p = Promise.resolve(p) + } + p.then((fetchResult) => { + if (this.$loading.increase) { + this.$loading.increase(loadingIncrease) + } + }) + promises.push(p) + } + + return Promise.all(promises) + })) + + // If not redirected + if (!nextCalled) { + if (this.$loading.finish && !this.$loading.manual) { + this.$loading.finish() + } + + next() + } + } catch (err) { + const error = err || {} + if (error.message === 'ERR_REDIRECT') { + return this.$nuxt.$emit('routeChanged', to, from, error) + } + _lastPaths = [] + + globalHandleError(error) + + // Load error layout + let layout = (NuxtError.options || NuxtError).layout + if (typeof layout === 'function') { + layout = layout(app.context) + } + await this.loadLayout(layout) + + this.error(error) + this.$nuxt.$emit('routeChanged', to, from, error) + next() + } +} + +// Fix components format in matched, it's due to code-splitting of vue-router +function normalizeComponents (to, ___) { + flatMapComponents(to, (Component, _, match, key) => { + if (typeof Component === 'object' && !Component.options) { + // Updated via vue-router resolveAsyncComponents() + Component = Vue.extend(Component) + Component._Ctor = Component + match.components[key] = Component + } + return Component + }) +} + +function setLayoutForNextPage (to) { + // Set layout + let hasError = Boolean(this.$options.nuxt.err) + if (this._hadError && this._dateLastError === this.$options.nuxt.dateErr) { + hasError = false + } + let layout = hasError + ? (NuxtError.options || NuxtError).layout + : to.matched[0].components.default.options.layout + + if (typeof layout === 'function') { + layout = layout(app.context) + } + + this.setLayout(layout) +} + +function checkForErrors (app) { + // Hide error component if no error + if (app._hadError && app._dateLastError === app.$options.nuxt.dateErr) { + app.error() + } +} + +// When navigating on a different route but the same component is used, Vue.js +// Will not update the instance data, so we have to update $data ourselves +function fixPrepatch (to, ___) { + if (this._routeChanged === false && this._paramChanged === false && this._queryChanged === false) { + return + } + + const instances = getMatchedComponentsInstances(to) + const Components = getMatchedComponents(to) + + Vue.nextTick(() => { + instances.forEach((instance, i) => { + if (!instance || instance._isDestroyed) { + return + } + + if ( + instance.constructor._dataRefresh && + Components[i] === instance.constructor && + instance.$vnode.data.keepAlive !== true && + typeof instance.constructor.options.data === 'function' + ) { + const newData = instance.constructor.options.data.call(instance) + for (const key in newData) { + Vue.set(instance.$data, key, newData[key]) + } + + // Ensure to trigger scroll event after calling scrollBehavior + window.$nuxt.$nextTick(() => { + window.$nuxt.$emit('triggerScroll') + }) + } + }) + checkForErrors(this) + }) +} + +function nuxtReady (_app) { + window.onNuxtReadyCbs.forEach((cb) => { + if (typeof cb === 'function') { + cb(_app) + } + }) + // Special JSDOM + if (typeof window._onNuxtLoaded === 'function') { + window._onNuxtLoaded(_app) + } + // Add router hooks + router.afterEach((to, from) => { + // Wait for fixPrepatch + $data updates + Vue.nextTick(() => _app.$nuxt.$emit('routeChanged', to, from)) + }) +} + +async function mountApp (__app) { + // Set global variables + app = __app.app + router = __app.router + + // Create Vue instance + const _app = new Vue(app) + + // Mounts Vue app to DOM element + const mount = () => { + _app.$mount('#__nuxt') + + // Add afterEach router hooks + router.afterEach(normalizeComponents) + + router.afterEach(setLayoutForNextPage.bind(_app)) + + router.afterEach(fixPrepatch.bind(_app)) + + // Listen for first Vue update + Vue.nextTick(() => { + // Call window.{{globals.readyCallback}} callbacks + nuxtReady(_app) + }) + } + + // Resolve route components + const Components = await Promise.all(resolveComponents(router)) + + // Enable transitions + _app.setTransitions = _app.$options.nuxt.setTransitions.bind(_app) + if (Components.length) { + _app.setTransitions(mapTransitions(Components, router.currentRoute)) + _lastPaths = router.currentRoute.matched.map(route => compile(route.path)(router.currentRoute.params)) + } + + // Initialize error handler + _app.$loading = {} // To avoid error while _app.$nuxt does not exist + if (NUXT.error) { + _app.error(NUXT.error) + } + + // Add beforeEach router hooks + router.beforeEach(loadAsyncComponents.bind(_app)) + router.beforeEach(render.bind(_app)) + + // Fix in static: remove trailing slash to force hydration + // Full static, if server-rendered: hydrate, to allow custom redirect to generated page + + // Fix in static: remove trailing slash to force hydration + if (NUXT.serverRendered && isSamePath(NUXT.routePath, _app.context.route.path)) { + return mount() + } + + // First render on client-side + const clientFirstMount = () => { + normalizeComponents(router.currentRoute, router.currentRoute) + setLayoutForNextPage.call(_app, router.currentRoute) + checkForErrors(_app) + // Don't call fixPrepatch.call(_app, router.currentRoute, router.currentRoute) since it's first render + mount() + } + + // fix: force next tick to avoid having same timestamp when an error happen on spa fallback + await new Promise(resolve => setTimeout(resolve, 0)) + render.call(_app, router.currentRoute, router.currentRoute, (path) => { + // If not redirected + if (!path) { + clientFirstMount() + return + } + + // Add a one-time afterEach hook to + // mount the app wait for redirect and route gets resolved + const unregisterHook = router.afterEach((to, from) => { + unregisterHook() + clientFirstMount() + }) + + // Push the path and let route to be resolved + router.push(path, undefined, (err) => { + if (err) { + errorHandler(err) + } + }) + }) +} diff --git a/.nuxt/components/nuxt-child.js b/.nuxt/components/nuxt-child.js new file mode 100644 index 0000000..af27a4d --- /dev/null +++ b/.nuxt/components/nuxt-child.js @@ -0,0 +1,122 @@ + +export default { + name: 'NuxtChild', + functional: true, + props: { + nuxtChildKey: { + type: String, + default: '' + }, + keepAlive: Boolean, + keepAliveProps: { + type: Object, + default: undefined + } + }, + render (_, { parent, data, props }) { + const h = parent.$createElement + + data.nuxtChild = true + const _parent = parent + const transitions = parent.$nuxt.nuxt.transitions + const defaultTransition = parent.$nuxt.nuxt.defaultTransition + + let depth = 0 + while (parent) { + if (parent.$vnode && parent.$vnode.data.nuxtChild) { + depth++ + } + parent = parent.$parent + } + data.nuxtChildDepth = depth + const transition = transitions[depth] || defaultTransition + const transitionProps = {} + transitionsKeys.forEach((key) => { + if (typeof transition[key] !== 'undefined') { + transitionProps[key] = transition[key] + } + }) + + const listeners = {} + listenersKeys.forEach((key) => { + if (typeof transition[key] === 'function') { + listeners[key] = transition[key].bind(_parent) + } + }) + if (process.client) { + // Add triggerScroll event on beforeEnter (fix #1376) + const beforeEnter = listeners.beforeEnter + listeners.beforeEnter = (el) => { + // Ensure to trigger scroll event after calling scrollBehavior + window.$nuxt.$nextTick(() => { + window.$nuxt.$emit('triggerScroll') + }) + if (beforeEnter) { + return beforeEnter.call(_parent, el) + } + } + } + + // make sure that leave is called asynchronous (fix #5703) + if (transition.css === false) { + const leave = listeners.leave + + // only add leave listener when user didnt provide one + // or when it misses the done argument + if (!leave || leave.length < 2) { + listeners.leave = (el, done) => { + if (leave) { + leave.call(_parent, el) + } + + _parent.$nextTick(done) + } + } + } + + let routerView = h('routerView', data) + + if (props.keepAlive) { + routerView = h('keep-alive', { props: props.keepAliveProps }, [routerView]) + } + + return h('transition', { + props: transitionProps, + on: listeners + }, [routerView]) + } +} + +const transitionsKeys = [ + 'name', + 'mode', + 'appear', + 'css', + 'type', + 'duration', + 'enterClass', + 'leaveClass', + 'appearClass', + 'enterActiveClass', + 'enterActiveClass', + 'leaveActiveClass', + 'appearActiveClass', + 'enterToClass', + 'leaveToClass', + 'appearToClass' +] + +const listenersKeys = [ + 'beforeEnter', + 'enter', + 'afterEnter', + 'enterCancelled', + 'beforeLeave', + 'leave', + 'afterLeave', + 'leaveCancelled', + 'beforeAppear', + 'appear', + 'afterAppear', + 'appearCancelled' +] diff --git a/.nuxt/components/nuxt-error.vue b/.nuxt/components/nuxt-error.vue new file mode 100644 index 0000000..b00af6a --- /dev/null +++ b/.nuxt/components/nuxt-error.vue @@ -0,0 +1,96 @@ + + + + + diff --git a/.nuxt/components/nuxt-link.client.js b/.nuxt/components/nuxt-link.client.js new file mode 100644 index 0000000..062a698 --- /dev/null +++ b/.nuxt/components/nuxt-link.client.js @@ -0,0 +1,98 @@ +import Vue from 'vue' + +const requestIdleCallback = window.requestIdleCallback || + function (cb) { + const start = Date.now() + return setTimeout(function () { + cb({ + didTimeout: false, + timeRemaining: () => Math.max(0, 50 - (Date.now() - start)) + }) + }, 1) + } + +const cancelIdleCallback = window.cancelIdleCallback || function (id) { + clearTimeout(id) +} + +const observer = window.IntersectionObserver && new window.IntersectionObserver((entries) => { + entries.forEach(({ intersectionRatio, target: link }) => { + if (intersectionRatio <= 0) { + return + } + link.__prefetch() + }) +}) + +export default { + name: 'NuxtLink', + extends: Vue.component('RouterLink'), + props: { + prefetch: { + type: Boolean, + default: true + }, + noPrefetch: { + type: Boolean, + default: false + } + }, + mounted () { + if (this.prefetch && !this.noPrefetch) { + this.handleId = requestIdleCallback(this.observe, { timeout: 2e3 }) + } + }, + beforeDestroy () { + cancelIdleCallback(this.handleId) + + if (this.__observed) { + observer.unobserve(this.$el) + delete this.$el.__prefetch + } + }, + methods: { + observe () { + // If no IntersectionObserver, avoid prefetching + if (!observer) { + return + } + // Add to observer + if (this.shouldPrefetch()) { + this.$el.__prefetch = this.prefetchLink.bind(this) + observer.observe(this.$el) + this.__observed = true + } + }, + shouldPrefetch () { + return this.getPrefetchComponents().length > 0 + }, + canPrefetch () { + const conn = navigator.connection + const hasBadConnection = this.$nuxt.isOffline || (conn && ((conn.effectiveType || '').includes('2g') || conn.saveData)) + + return !hasBadConnection + }, + getPrefetchComponents () { + const ref = this.$router.resolve(this.to, this.$route, this.append) + const Components = ref.resolved.matched.map(r => r.components.default) + + return Components.filter(Component => typeof Component === 'function' && !Component.options && !Component.__prefetched) + }, + prefetchLink () { + if (!this.canPrefetch()) { + return + } + // Stop observing this link (in case of internet connection changes) + observer.unobserve(this.$el) + const Components = this.getPrefetchComponents() + + for (const Component of Components) { + const componentOrPromise = Component() + if (componentOrPromise instanceof Promise) { + componentOrPromise.catch(() => {}) + } + Component.__prefetched = true + } + } + } +} diff --git a/.nuxt/components/nuxt-link.server.js b/.nuxt/components/nuxt-link.server.js new file mode 100644 index 0000000..f123090 --- /dev/null +++ b/.nuxt/components/nuxt-link.server.js @@ -0,0 +1,16 @@ +import Vue from 'vue' + +export default { + name: 'NuxtLink', + extends: Vue.component('RouterLink'), + props: { + prefetch: { + type: Boolean, + default: true + }, + noPrefetch: { + type: Boolean, + default: false + } + } +} diff --git a/.nuxt/components/nuxt-loading.vue b/.nuxt/components/nuxt-loading.vue new file mode 100644 index 0000000..cc0d98e --- /dev/null +++ b/.nuxt/components/nuxt-loading.vue @@ -0,0 +1,177 @@ + + + diff --git a/.nuxt/components/nuxt.js b/.nuxt/components/nuxt.js new file mode 100644 index 0000000..dc79c20 --- /dev/null +++ b/.nuxt/components/nuxt.js @@ -0,0 +1,101 @@ +import Vue from 'vue' +import { compile } from '../utils' + +import NuxtError from './nuxt-error.vue' + +import NuxtChild from './nuxt-child' + +export default { + name: 'Nuxt', + components: { + NuxtChild, + NuxtError + }, + props: { + nuxtChildKey: { + type: String, + default: undefined + }, + keepAlive: Boolean, + keepAliveProps: { + type: Object, + default: undefined + }, + name: { + type: String, + default: 'default' + } + }, + errorCaptured (error) { + // if we receive and error while showing the NuxtError component + // capture the error and force an immediate update so we re-render + // without the NuxtError component + if (this.displayingNuxtError) { + this.errorFromNuxtError = error + this.$forceUpdate() + } + }, + computed: { + routerViewKey () { + // If nuxtChildKey prop is given or current route has children + if (typeof this.nuxtChildKey !== 'undefined' || this.$route.matched.length > 1) { + return this.nuxtChildKey || compile(this.$route.matched[0].path)(this.$route.params) + } + + const [matchedRoute] = this.$route.matched + + if (!matchedRoute) { + return this.$route.path + } + + const Component = matchedRoute.components.default + + if (Component && Component.options) { + const { options } = Component + + if (options.key) { + return (typeof options.key === 'function' ? options.key(this.$route) : options.key) + } + } + + const strict = /\/$/.test(matchedRoute.path) + return strict ? this.$route.path : this.$route.path.replace(/\/$/, '') + } + }, + beforeCreate () { + Vue.util.defineReactive(this, 'nuxt', this.$root.$options.nuxt) + }, + render (h) { + // if there is no error + if (!this.nuxt.err) { + // Directly return nuxt child + return h('NuxtChild', { + key: this.routerViewKey, + props: this.$props + }) + } + + // if an error occurred within NuxtError show a simple + // error message instead to prevent looping + if (this.errorFromNuxtError) { + this.$nextTick(() => (this.errorFromNuxtError = false)) + + return h('div', {}, [ + h('h2', 'An error occurred while showing the error page'), + h('p', 'Unfortunately an error occurred and while showing the error page another error occurred'), + h('p', `Error details: ${this.errorFromNuxtError.toString()}`), + h('nuxt-link', { props: { to: '/' } }, 'Go back to home') + ]) + } + + // track if we are showing the NuxtError component + this.displayingNuxtError = true + this.$nextTick(() => (this.displayingNuxtError = false)) + + return h(NuxtError, { + props: { + error: this.nuxt.err + } + }) + } +} diff --git a/.nuxt/empty.js b/.nuxt/empty.js new file mode 100644 index 0000000..a3ac0d8 --- /dev/null +++ b/.nuxt/empty.js @@ -0,0 +1 @@ +// This file is intentionally left empty for noop aliases diff --git a/.nuxt/index.js b/.nuxt/index.js new file mode 100644 index 0000000..349b769 --- /dev/null +++ b/.nuxt/index.js @@ -0,0 +1,216 @@ +import Vue from 'vue' + +import Meta from 'vue-meta' +import ClientOnly from 'vue-client-only' +import NoSsr from 'vue-no-ssr' +import { createRouter } from './router.js' +import NuxtChild from './components/nuxt-child.js' +import NuxtError from './components/nuxt-error.vue' +import Nuxt from './components/nuxt.js' +import App from './App.js' +import { setContext, getLocation, getRouteData, normalizeError } from './utils' + +/* Plugins */ + +import nuxt_plugin_nuxtsvgsprite_9b1bd69a from 'nuxt_plugin_nuxtsvgsprite_9b1bd69a' // Source: ./nuxt-svg-sprite.js (mode: 'all') +import nuxt_plugin_datajson_0541d330 from 'nuxt_plugin_datajson_0541d330' // Source: ../data/index/data.json.js (mode: 'client') +import nuxt_plugin_index_5e7689d9 from 'nuxt_plugin_index_5e7689d9' // Source: ../plugins/index.js (mode: 'client') + +// Component: +Vue.component(ClientOnly.name, ClientOnly) + +// TODO: Remove in Nuxt 3: +Vue.component(NoSsr.name, { + ...NoSsr, + render (h, ctx) { + if (process.client && !NoSsr._warned) { + NoSsr._warned = true + + console.warn(' has been deprecated and will be removed in Nuxt 3, please use instead') + } + return NoSsr.render(h, ctx) + } +}) + +// Component: +Vue.component(NuxtChild.name, NuxtChild) +Vue.component('NChild', NuxtChild) + +// Component NuxtLink is imported in server.js or client.js + +// Component: +Vue.component(Nuxt.name, Nuxt) + +Vue.use(Meta, {"keyName":"head","attribute":"data-n-head","ssrAttribute":"data-n-head-ssr","tagIDKeyName":"hid"}) + +const defaultTransition = {"name":"page","mode":"out-in","appear":true,"appearClass":"appear","appearActiveClass":"appear-active","appearToClass":"appear-to"} + +async function createApp(ssrContext, config = {}) { + const router = await createRouter(ssrContext) + + // Create Root instance + + // here we inject the router and store to all child components, + // making them available everywhere as `this.$router` and `this.$store`. + const app = { + head: {"title":"Shift Project","meta":[{"charset":"utf-8"},{"name":"viewport","content":"width=device-width, initial-scale=1"},{"hid":"description","name":"description","content":"Shift combines the transparency, immutability and decentralization of blockchain with the distributed hosting of the InterPlanetary File System"}],"link":[{"rel":"icon","type":"image\u002Fx-icon","href":"\u002Ffavicon.ico"}],"style":[],"script":[]}, + + router, + nuxt: { + defaultTransition, + transitions: [defaultTransition], + setTransitions (transitions) { + if (!Array.isArray(transitions)) { + transitions = [transitions] + } + transitions = transitions.map((transition) => { + if (!transition) { + transition = defaultTransition + } else if (typeof transition === 'string') { + transition = Object.assign({}, defaultTransition, { name: transition }) + } else { + transition = Object.assign({}, defaultTransition, transition) + } + return transition + }) + this.$options.nuxt.transitions = transitions + return transitions + }, + + err: null, + dateErr: null, + error (err) { + err = err || null + app.context._errored = Boolean(err) + err = err ? normalizeError(err) : null + let nuxt = app.nuxt // to work with @vue/composition-api, see https://github.com/nuxt/nuxt.js/issues/6517#issuecomment-573280207 + if (this) { + nuxt = this.nuxt || this.$options.nuxt + } + nuxt.dateErr = Date.now() + nuxt.err = err + // Used in src/server.js + if (ssrContext) { + ssrContext.nuxt.error = err + } + return err + } + }, + ...App + } + + const next = ssrContext ? ssrContext.next : location => app.router.push(location) + // Resolve route + let route + if (ssrContext) { + route = router.resolve(ssrContext.url).route + } else { + const path = getLocation(router.options.base, router.options.mode) + route = router.resolve(path).route + } + + // Set context to app.context + await setContext(app, { + route, + next, + error: app.nuxt.error.bind(app), + payload: ssrContext ? ssrContext.payload : undefined, + req: ssrContext ? ssrContext.req : undefined, + res: ssrContext ? ssrContext.res : undefined, + beforeRenderFns: ssrContext ? ssrContext.beforeRenderFns : undefined, + ssrContext + }) + + function inject(key, value) { + if (!key) { + throw new Error('inject(key, value) has no key provided') + } + if (value === undefined) { + throw new Error(`inject('${key}', value) has no value provided`) + } + + key = '$' + key + // Add into app + app[key] = value + // Add into context + if (!app.context[key]) { + app.context[key] = value + } + + // Check if plugin not already installed + const installKey = '__nuxt_' + key + '_installed__' + if (Vue[installKey]) { + return + } + Vue[installKey] = true + // Call Vue.use() to install the plugin into vm + Vue.use(() => { + if (!Object.prototype.hasOwnProperty.call(Vue.prototype, key)) { + Object.defineProperty(Vue.prototype, key, { + get () { + return this.$root.$options[key] + } + }) + } + }) + } + + // Inject runtime config as $config + inject('config', config) + + // Add enablePreview(previewData = {}) in context for plugins + if (process.static && process.client) { + app.context.enablePreview = function (previewData = {}) { + app.previewData = Object.assign({}, previewData) + inject('preview', previewData) + } + } + // Plugin execution + + if (typeof nuxt_plugin_nuxtsvgsprite_9b1bd69a === 'function') { + await nuxt_plugin_nuxtsvgsprite_9b1bd69a(app.context, inject) + } + + if (process.client && typeof nuxt_plugin_datajson_0541d330 === 'function') { + await nuxt_plugin_datajson_0541d330(app.context, inject) + } + + if (process.client && typeof nuxt_plugin_index_5e7689d9 === 'function') { + await nuxt_plugin_index_5e7689d9(app.context, inject) + } + + // Lock enablePreview in context + if (process.static && process.client) { + app.context.enablePreview = function () { + console.warn('You cannot call enablePreview() outside a plugin.') + } + } + + // If server-side, wait for async component to be resolved first + if (process.server && ssrContext && ssrContext.url) { + await new Promise((resolve, reject) => { + router.push(ssrContext.url, resolve, (err) => { + // https://github.com/vuejs/vue-router/blob/v3.4.3/src/util/errors.js + if (!err._isRouter) return reject(err) + if (err.type !== 2 /* NavigationFailureType.redirected */) return resolve() + + // navigated to a different route in router guard + const unregister = router.afterEach(async (to, from) => { + ssrContext.url = to.fullPath + app.context.route = await getRouteData(to) + app.context.params = to.params || {} + app.context.query = to.query || {} + unregister() + resolve() + }) + }) + }) + } + + return { + app, + router + } +} + +export { createApp, NuxtError } diff --git a/.nuxt/jsonp.js b/.nuxt/jsonp.js new file mode 100644 index 0000000..4969d72 --- /dev/null +++ b/.nuxt/jsonp.js @@ -0,0 +1,80 @@ +const chunks = {} // chunkId => exports +const chunksInstalling = {} // chunkId => Promise +const failedChunks = {} + +function importChunk(chunkId, src) { + // Already installed + if (chunks[chunkId]) { + return Promise.resolve(chunks[chunkId]) + } + + // Failed loading + if (failedChunks[chunkId]) { + return Promise.reject(failedChunks[chunkId]) + } + + // Installing + if (chunksInstalling[chunkId]) { + return chunksInstalling[chunkId] + } + + // Set a promise in chunk cache + let resolve, reject + const promise = chunksInstalling[chunkId] = new Promise((_resolve, _reject) => { + resolve = _resolve + reject = _reject + }) + + // Clear chunk data from cache + delete chunks[chunkId] + + // Start chunk loading + const script = document.createElement('script') + script.charset = 'utf-8' + script.timeout = 120 + script.src = src + let timeout + + // Create error before stack unwound to get useful stacktrace later + const error = new Error() + + // Complete handlers + const onScriptComplete = script.onerror = script.onload = (event) => { + // Cleanups + clearTimeout(timeout) + delete chunksInstalling[chunkId] + + // Avoid mem leaks in IE + script.onerror = script.onload = null + + // Verify chunk is loaded + if (chunks[chunkId]) { + return resolve(chunks[chunkId]) + } + + // Something bad happened + const errorType = event && (event.type === 'load' ? 'missing' : event.type) + const realSrc = event && event.target && event.target.src + error.message = 'Loading chunk ' + chunkId + ' failed.\n(' + errorType + ': ' + realSrc + ')' + error.name = 'ChunkLoadError' + error.type = errorType + error.request = realSrc + failedChunks[chunkId] = error + reject(error) + } + + // Timeout + timeout = setTimeout(() => { + onScriptComplete({ type: 'timeout', target: script }) + }, 120000) + + // Append script + document.head.appendChild(script) + + // Return promise + return promise +} + +window.__NUXT_JSONP__ = function (chunkId, exports) { chunks[chunkId] = exports } +window.__NUXT_JSONP_CACHE__ = chunks +window.__NUXT_IMPORT__ = importChunk diff --git a/.nuxt/loading.html b/.nuxt/loading.html new file mode 100644 index 0000000..768b8b3 --- /dev/null +++ b/.nuxt/loading.html @@ -0,0 +1,108 @@ + + + + +
Loading...
diff --git a/.nuxt/middleware.js b/.nuxt/middleware.js new file mode 100644 index 0000000..343ef95 --- /dev/null +++ b/.nuxt/middleware.js @@ -0,0 +1,3 @@ +const middleware = {} + +export default middleware diff --git a/.nuxt/mixins/fetch.client.js b/.nuxt/mixins/fetch.client.js new file mode 100644 index 0000000..1644ac7 --- /dev/null +++ b/.nuxt/mixins/fetch.client.js @@ -0,0 +1,90 @@ +import Vue from 'vue' +import { hasFetch, normalizeError, addLifecycleHook } from '../utils' + +const isSsrHydration = (vm) => vm.$vnode && vm.$vnode.elm && vm.$vnode.elm.dataset && vm.$vnode.elm.dataset.fetchKey +const nuxtState = window.__NUXT__ + +export default { + beforeCreate () { + if (!hasFetch(this)) { + return + } + + this._fetchDelay = typeof this.$options.fetchDelay === 'number' ? this.$options.fetchDelay : 200 + + Vue.util.defineReactive(this, '$fetchState', { + pending: false, + error: null, + timestamp: Date.now() + }) + + this.$fetch = $fetch.bind(this) + addLifecycleHook(this, 'created', created) + addLifecycleHook(this, 'beforeMount', beforeMount) + } +} + +function beforeMount() { + if (!this._hydrated) { + return this.$fetch() + } +} + +function created() { + if (!isSsrHydration(this)) { + return + } + + // Hydrate component + this._hydrated = true + this._fetchKey = +this.$vnode.elm.dataset.fetchKey + const data = nuxtState.fetch[this._fetchKey] + + // If fetch error + if (data && data._error) { + this.$fetchState.error = data._error + return + } + + // Merge data + for (const key in data) { + Vue.set(this.$data, key, data[key]) + } +} + +function $fetch() { + if (!this._fetchPromise) { + this._fetchPromise = $_fetch.call(this) + .then(() => { delete this._fetchPromise }) + } + return this._fetchPromise +} + +async function $_fetch() { + this.$nuxt.nbFetching++ + this.$fetchState.pending = true + this.$fetchState.error = null + this._hydrated = false + let error = null + const startTime = Date.now() + + try { + await this.$options.fetch.call(this) + } catch (err) { + if (process.dev) { + console.error('Error in fetch():', err) + } + error = normalizeError(err) + } + + const delayLeft = this._fetchDelay - (Date.now() - startTime) + if (delayLeft > 0) { + await new Promise(resolve => setTimeout(resolve, delayLeft)) + } + + this.$fetchState.error = error + this.$fetchState.pending = false + this.$fetchState.timestamp = Date.now() + + this.$nextTick(() => this.$nuxt.nbFetching--) +} diff --git a/.nuxt/mixins/fetch.server.js b/.nuxt/mixins/fetch.server.js new file mode 100644 index 0000000..89b0341 --- /dev/null +++ b/.nuxt/mixins/fetch.server.js @@ -0,0 +1,51 @@ +import Vue from 'vue' +import { hasFetch, normalizeError, addLifecycleHook } from '../utils' + +async function serverPrefetch() { + if (!this._fetchOnServer) { + return + } + + // Call and await on $fetch + try { + await this.$options.fetch.call(this) + } catch (err) { + if (process.dev) { + console.error('Error in fetch():', err) + } + this.$fetchState.error = normalizeError(err) + } + this.$fetchState.pending = false + + // Define an ssrKey for hydration + this._fetchKey = this.$ssrContext.nuxt.fetch.length + + // Add data-fetch-key on parent element of Component + const attrs = this.$vnode.data.attrs = this.$vnode.data.attrs || {} + attrs['data-fetch-key'] = this._fetchKey + + // Add to ssrContext for window.__NUXT__.fetch + this.$ssrContext.nuxt.fetch.push(this.$fetchState.error ? { _error: this.$fetchState.error } : this._data) +} + +export default { + created() { + if (!hasFetch(this)) { + return + } + + if (typeof this.$options.fetchOnServer === 'function') { + this._fetchOnServer = this.$options.fetchOnServer.call(this) !== false + } else { + this._fetchOnServer = this.$options.fetchOnServer !== false + } + + Vue.util.defineReactive(this, '$fetchState', { + pending: true, + error: null, + timestamp: Date.now() + }) + + addLifecycleHook(this, 'serverPrefetch', serverPrefetch) + } +} diff --git a/.nuxt/nuxt-svg-sprite.js b/.nuxt/nuxt-svg-sprite.js new file mode 100644 index 0000000..af54984 --- /dev/null +++ b/.nuxt/nuxt-svg-sprite.js @@ -0,0 +1,107 @@ +import Vue from 'vue' +import { mergeData } from 'vue-functional-data-merge' + +function generateName (name) { + return name + .toLowerCase() + .replace(/\.svg$/, '') + .replace(/[^a-z0-9-]/g, '-') +} + +/** + * Find sprite file name after nuxt build + * @param {string} sprite Name of a sprite + */ +function getSpritePath (sprite) { + const module = require('~/assets/sprite/gen/' + sprite + '.svg') + if (typeof module === 'string') { + return module + } + // nuxt-edge v3.0.0-26398097.20b0379b returns object instead of string + if (typeof module === 'object' && typeof module.default === 'string') { + return module.default + } + return '' +} + +function getIcon (info) { + const { icon, sprite } = info + + return getSpritePath(sprite) + `#i-${generateName(icon)}` +} + +function getInfo (name) { + let [sprite, icon] = name.split('/') + + if (!icon) { + icon = sprite + sprite = 'icons' + } + + return { + icon, + sprite + } +} + +// @vue/component +const SvgIcon = { + name: 'SvgIcon', + functional: true, + props: { + name: { + type: String, + required: true + }, + title: { + type: String, + default: null + }, + desc: { + type: String, + default: null + }, + viewBox: { + type: String, + default: null, + validator (value) { + return value.split(' ').every((v) => { + return !isNaN(parseInt(v)) + }) + } + } + }, + render (h, { props, data }) { + const info = getInfo(props.name) + const icon = getIcon(info) + + const use = h('use', { + attrs: { + // Since SVG 2, the xlink:href attribute is deprecated in favor of simply href. + href: icon, + // xlink:href can still be required in practice for cross-browser compatibility. + 'xlink:href': icon + } + }) + + const title = props.title ? h('title', props.title) : null + const desc = props.desc ? h('desc', props.desc) : null + + const { sprite } = info + + const componentData = { + class: 'icon sprite-' + sprite, + attrs: { + xmlns: 'http://www.w3.org/2000/svg', + viewBox: props.viewBox + } + } + + return h('svg', + mergeData(data, componentData), + [title, desc, use].filter(Boolean) + ) + } +} + +Vue.component(SvgIcon.name, SvgIcon) diff --git a/.nuxt/router.js b/.nuxt/router.js new file mode 100644 index 0000000..c9a7606 --- /dev/null +++ b/.nuxt/router.js @@ -0,0 +1,40 @@ +import Vue from 'vue' +import Router from 'vue-router' +import { interopDefault } from './utils' +import scrollBehavior from './router.scrollBehavior.js' + +const _dc8231dc = () => interopDefault(import('../pages/news/:id.vue' /* webpackChunkName: "pages/news/:id" */)) +const _e39f6aae = () => interopDefault(import('../pages/index.vue' /* webpackChunkName: "pages/index" */)) + +// TODO: remove in Nuxt 3 +const emptyFn = () => {} +const originalPush = Router.prototype.push +Router.prototype.push = function push (location, onComplete = emptyFn, onAbort) { + return originalPush.call(this, location, onComplete, onAbort) +} + +Vue.use(Router) + +export const routerOptions = { + mode: 'history', + base: decodeURI('/'), + linkActiveClass: 'nuxt-link-active', + linkExactActiveClass: 'nuxt-link-exact-active', + scrollBehavior, + + routes: [{ + path: "/news/:id", + component: _dc8231dc, + name: "news-:id" + }, { + path: "/", + component: _e39f6aae, + name: "index" + }], + + fallback: false +} + +export function createRouter () { + return new Router(routerOptions) +} diff --git a/.nuxt/router.scrollBehavior.js b/.nuxt/router.scrollBehavior.js new file mode 100644 index 0000000..ade64e8 --- /dev/null +++ b/.nuxt/router.scrollBehavior.js @@ -0,0 +1,76 @@ +import { getMatchedComponents } from './utils' + +if (process.client) { + if ('scrollRestoration' in window.history) { + window.history.scrollRestoration = 'manual' + + // reset scrollRestoration to auto when leaving page, allowing page reload + // and back-navigation from other pages to use the browser to restore the + // scrolling position. + window.addEventListener('beforeunload', () => { + window.history.scrollRestoration = 'auto' + }) + + // Setting scrollRestoration to manual again when returning to this page. + window.addEventListener('load', () => { + window.history.scrollRestoration = 'manual' + }) + } +} + + export default function (to, from, savedPosition) { + // If the returned position is falsy or an empty object, will retain current scroll position + let position = false + + const Pages = getMatchedComponents(to) + + // Scroll to the top of the page if... + if ( + // One of the children set `scrollToTop` + Pages.some(Page => Page.options.scrollToTop) || + // scrollToTop set in only page without children + (Pages.length < 2 && Pages.every(Page => Page.options.scrollToTop !== false)) + ) { + position = { x: 0, y: 0 } + } + + // savedPosition is only available for popstate navigations (back button) + if (savedPosition) { + position = savedPosition + } + + const nuxt = window.$nuxt + + if ( + // Route hash changes + (to.path === from.path && to.hash !== from.hash) || + // Initial load (vuejs/vue-router#3199) + to === from + ) { + nuxt.$nextTick(() => nuxt.$emit('triggerScroll')) + } + + return new Promise((resolve) => { + // wait for the out transition to complete (if necessary) + nuxt.$once('triggerScroll', () => { + // coords will be used if no selector is provided, + // or if the selector didn't match any element. + if (to.hash) { + let hash = to.hash + // CSS.escape() is not supported with IE and Edge. + if (typeof window.CSS !== 'undefined' && typeof window.CSS.escape !== 'undefined') { + hash = '#' + window.CSS.escape(hash.substr(1)) + } + try { + if (document.querySelector(hash)) { + // scroll to anchor by returning the selector + position = { selector: hash } + } + } catch (e) { + console.warn('Failed to save scroll position. Please add CSS.escape() polyfill (https://github.com/mathiasbynens/CSS.escape).') + } + } + resolve(position) + }) + }) +} diff --git a/.nuxt/routes.json b/.nuxt/routes.json new file mode 100644 index 0000000..2dc61c0 --- /dev/null +++ b/.nuxt/routes.json @@ -0,0 +1,16 @@ +[ + { + "name": "news-:id", + "path": "/news/:id", + "component": "/Users/matthewswezy/GitHub/shift-website/pages/news/:id.vue", + "chunkName": "pages/news/:id", + "_name": "_dc8231dc" + }, + { + "name": "index", + "path": "/", + "component": "/Users/matthewswezy/GitHub/shift-website/pages/index.vue", + "chunkName": "pages/index", + "_name": "_e39f6aae" + } +] diff --git a/.nuxt/server.js b/.nuxt/server.js new file mode 100644 index 0000000..bc8b104 --- /dev/null +++ b/.nuxt/server.js @@ -0,0 +1,268 @@ +import { stringify } from 'querystring' +import Vue from 'vue' +import fetch from 'node-fetch' +import middleware from './middleware.js' +import { + applyAsyncData, + middlewareSeries, + sanitizeComponent, + getMatchedComponents, + promisify +} from './utils.js' +import fetchMixin from './mixins/fetch.server' +import { createApp, NuxtError } from './index.js' +import NuxtLink from './components/nuxt-link.server.js' // should be included after ./index.js + +// Update serverPrefetch strategy +Vue.config.optionMergeStrategies.serverPrefetch = Vue.config.optionMergeStrategies.created + +// Fetch mixin +if (!Vue.__nuxt__fetch__mixin__) { + Vue.mixin(fetchMixin) + Vue.__nuxt__fetch__mixin__ = true +} + +// Component: +Vue.component(NuxtLink.name, NuxtLink) +Vue.component('NLink', NuxtLink) + +if (!global.fetch) { global.fetch = fetch } + +const noopApp = () => new Vue({ render: h => h('div') }) + +function urlJoin () { + return Array.prototype.slice.call(arguments).join('/').replace(/\/+/g, '/') +} + +const createNext = ssrContext => (opts) => { + // If static target, render on client-side + ssrContext.redirected = opts + if (ssrContext.target === 'static' || !ssrContext.res) { + ssrContext.nuxt.serverRendered = false + return + } + opts.query = stringify(opts.query) + opts.path = opts.path + (opts.query ? '?' + opts.query : '') + const routerBase = '/' + if (!opts.path.startsWith('http') && (routerBase !== '/' && !opts.path.startsWith(routerBase))) { + opts.path = urlJoin(routerBase, opts.path) + } + // Avoid loop redirect + if (opts.path === ssrContext.url) { + ssrContext.redirected = false + return + } + ssrContext.res.writeHead(opts.status, { + Location: opts.path + }) + ssrContext.res.end() +} + +// This exported function will be called by `bundleRenderer`. +// This is where we perform data-prefetching to determine the +// state of our application before actually rendering it. +// Since data fetching is async, this function is expected to +// return a Promise that resolves to the app instance. +export default async (ssrContext) => { + // Create ssrContext.next for simulate next() of beforeEach() when wanted to redirect + ssrContext.redirected = false + ssrContext.next = createNext(ssrContext) + // Used for beforeNuxtRender({ Components, nuxtState }) + ssrContext.beforeRenderFns = [] + // Nuxt object (window.{{globals.context}}, defaults to window.__NUXT__) + ssrContext.nuxt = { layout: 'default', data: [], fetch: [], error: null, serverRendered: true, routePath: '' } + // Remove query from url is static target + if (process.static && ssrContext.url) { + ssrContext.url = ssrContext.url.split('?')[0] + } + // Public runtime config + ssrContext.nuxt.config = ssrContext.runtimeConfig.public + // Create the app definition and the instance (created for each request) + const { app, router } = await createApp(ssrContext, { ...ssrContext.runtimeConfig.public, ...ssrContext.runtimeConfig.private }) + const _app = new Vue(app) + // Add ssr route path to nuxt context so we can account for page navigation between ssr and csr + ssrContext.nuxt.routePath = app.context.route.path + + // Add meta infos (used in renderer.js) + ssrContext.meta = _app.$meta() + + // Keep asyncData for each matched component in ssrContext (used in app/utils.js via this.$ssrContext) + ssrContext.asyncData = {} + + const beforeRender = async () => { + // Call beforeNuxtRender() methods + await Promise.all(ssrContext.beforeRenderFns.map(fn => promisify(fn, { Components, nuxtState: ssrContext.nuxt }))) + } + + const renderErrorPage = async () => { + // Don't server-render the page in static target + if (ssrContext.target === 'static') { + ssrContext.nuxt.serverRendered = false + } + + // Load layout for error page + const layout = (NuxtError.options || NuxtError).layout + const errLayout = typeof layout === 'function' ? layout.call(NuxtError, app.context) : layout + ssrContext.nuxt.layout = errLayout || 'default' + await _app.loadLayout(errLayout) + _app.setLayout(errLayout) + + await beforeRender() + return _app + } + const render404Page = () => { + app.context.error({ statusCode: 404, path: ssrContext.url, message: 'This page could not be found' }) + return renderErrorPage() + } + + // Components are already resolved by setContext -> getRouteData (app/utils.js) + const Components = getMatchedComponents(router.match(ssrContext.url)) + + /* + ** Call global middleware (nuxt.config.js) + */ + let midd = [] + midd = midd.map((name) => { + if (typeof name === 'function') { + return name + } + if (typeof middleware[name] !== 'function') { + app.context.error({ statusCode: 500, message: 'Unknown middleware ' + name }) + } + return middleware[name] + }) + await middlewareSeries(midd, app.context) + // ...If there is a redirect or an error, stop the process + if (ssrContext.redirected) { + return noopApp() + } + if (ssrContext.nuxt.error) { + return renderErrorPage() + } + + /* + ** Set layout + */ + let layout = Components.length ? Components[0].options.layout : NuxtError.layout + if (typeof layout === 'function') { + layout = layout(app.context) + } + await _app.loadLayout(layout) + if (ssrContext.nuxt.error) { + return renderErrorPage() + } + layout = _app.setLayout(layout) + ssrContext.nuxt.layout = _app.layoutName + + /* + ** Call middleware (layout + pages) + */ + midd = [] + + layout = sanitizeComponent(layout) + if (layout.options.middleware) { + midd = midd.concat(layout.options.middleware) + } + + Components.forEach((Component) => { + if (Component.options.middleware) { + midd = midd.concat(Component.options.middleware) + } + }) + midd = midd.map((name) => { + if (typeof name === 'function') { + return name + } + if (typeof middleware[name] !== 'function') { + app.context.error({ statusCode: 500, message: 'Unknown middleware ' + name }) + } + return middleware[name] + }) + await middlewareSeries(midd, app.context) + // ...If there is a redirect or an error, stop the process + if (ssrContext.redirected) { + return noopApp() + } + if (ssrContext.nuxt.error) { + return renderErrorPage() + } + + /* + ** Call .validate() + */ + let isValid = true + try { + for (const Component of Components) { + if (typeof Component.options.validate !== 'function') { + continue + } + + isValid = await Component.options.validate(app.context) + + if (!isValid) { + break + } + } + } catch (validationError) { + // ...If .validate() threw an error + app.context.error({ + statusCode: validationError.statusCode || '500', + message: validationError.message + }) + return renderErrorPage() + } + + // ...If .validate() returned false + if (!isValid) { + // Render a 404 error page + return render404Page() + } + + // If no Components found, returns 404 + if (!Components.length) { + return render404Page() + } + + // Call asyncData & fetch hooks on components matched by the route. + const asyncDatas = await Promise.all(Components.map((Component) => { + const promises = [] + + // Call asyncData(context) + if (Component.options.asyncData && typeof Component.options.asyncData === 'function') { + const promise = promisify(Component.options.asyncData, app.context) + promise.then((asyncDataResult) => { + ssrContext.asyncData[Component.cid] = asyncDataResult + applyAsyncData(Component) + return asyncDataResult + }) + promises.push(promise) + } else { + promises.push(null) + } + + // Call fetch(context) + if (Component.options.fetch && Component.options.fetch.length) { + promises.push(Component.options.fetch(app.context)) + } else { + promises.push(null) + } + + return Promise.all(promises) + })) + + // datas are the first row of each + ssrContext.nuxt.data = asyncDatas.map(r => r[0] || {}) + + // ...If there is a redirect or an error, stop the process + if (ssrContext.redirected) { + return noopApp() + } + if (ssrContext.nuxt.error) { + return renderErrorPage() + } + + // Call beforeNuxtRender methods & add store state + await beforeRender() + + return _app +} diff --git a/.nuxt/utils.js b/.nuxt/utils.js new file mode 100644 index 0000000..1177ad3 --- /dev/null +++ b/.nuxt/utils.js @@ -0,0 +1,634 @@ +import Vue from 'vue' + +// window.{{globals.loadedCallback}} hook +// Useful for jsdom testing or plugins (https://github.com/tmpvar/jsdom#dealing-with-asynchronous-script-loading) +if (process.client) { + window.onNuxtReadyCbs = [] + window.onNuxtReady = (cb) => { + window.onNuxtReadyCbs.push(cb) + } +} + +export function empty () {} + +export function globalHandleError (error) { + if (Vue.config.errorHandler) { + Vue.config.errorHandler(error) + } +} + +export function interopDefault (promise) { + return promise.then(m => m.default || m) +} + +export function hasFetch(vm) { + return vm.$options && typeof vm.$options.fetch === 'function' && !vm.$options.fetch.length +} +export function getChildrenComponentInstancesUsingFetch(vm, instances = []) { + const children = vm.$children || [] + for (const child of children) { + if (child.$fetch) { + instances.push(child) + continue; // Don't get the children since it will reload the template + } + if (child.$children) { + getChildrenComponentInstancesUsingFetch(child, instances) + } + } + return instances +} + +export function applyAsyncData (Component, asyncData) { + if ( + // For SSR, we once all this function without second param to just apply asyncData + // Prevent doing this for each SSR request + !asyncData && Component.options.__hasNuxtData + ) { + return + } + + const ComponentData = Component.options._originDataFn || Component.options.data || function () { return {} } + Component.options._originDataFn = ComponentData + + Component.options.data = function () { + const data = ComponentData.call(this, this) + if (this.$ssrContext) { + asyncData = this.$ssrContext.asyncData[Component.cid] + } + return { ...data, ...asyncData } + } + + Component.options.__hasNuxtData = true + + if (Component._Ctor && Component._Ctor.options) { + Component._Ctor.options.data = Component.options.data + } +} + +export function sanitizeComponent (Component) { + // If Component already sanitized + if (Component.options && Component._Ctor === Component) { + return Component + } + if (!Component.options) { + Component = Vue.extend(Component) // fix issue #6 + Component._Ctor = Component + } else { + Component._Ctor = Component + Component.extendOptions = Component.options + } + // If no component name defined, set file path as name, (also fixes #5703) + if (!Component.options.name && Component.options.__file) { + Component.options.name = Component.options.__file + } + return Component +} + +export function getMatchedComponents (route, matches = false, prop = 'components') { + return Array.prototype.concat.apply([], route.matched.map((m, index) => { + return Object.keys(m[prop]).map((key) => { + matches && matches.push(index) + return m[prop][key] + }) + })) +} + +export function getMatchedComponentsInstances (route, matches = false) { + return getMatchedComponents(route, matches, 'instances') +} + +export function flatMapComponents (route, fn) { + return Array.prototype.concat.apply([], route.matched.map((m, index) => { + return Object.keys(m.components).reduce((promises, key) => { + if (m.components[key]) { + promises.push(fn(m.components[key], m.instances[key], m, key, index)) + } else { + delete m.components[key] + } + return promises + }, []) + })) +} + +export function resolveRouteComponents (route, fn) { + return Promise.all( + flatMapComponents(route, async (Component, instance, match, key) => { + // If component is a function, resolve it + if (typeof Component === 'function' && !Component.options) { + Component = await Component() + } + match.components[key] = Component = sanitizeComponent(Component) + return typeof fn === 'function' ? fn(Component, instance, match, key) : Component + }) + ) +} + +export async function getRouteData (route) { + if (!route) { + return + } + // Make sure the components are resolved (code-splitting) + await resolveRouteComponents(route) + // Send back a copy of route with meta based on Component definition + return { + ...route, + meta: getMatchedComponents(route).map((Component, index) => { + return { ...Component.options.meta, ...(route.matched[index] || {}).meta } + }) + } +} + +export async function setContext (app, context) { + // If context not defined, create it + if (!app.context) { + app.context = { + isStatic: process.static, + isDev: false, + isHMR: false, + app, + + payload: context.payload, + error: context.error, + base: '/', + env: {} + } + // Only set once + if (!process.static && context.req) { + app.context.req = context.req + } + if (!process.static && context.res) { + app.context.res = context.res + } + if (context.ssrContext) { + app.context.ssrContext = context.ssrContext + } + app.context.redirect = (status, path, query) => { + if (!status) { + return + } + app.context._redirected = true + // if only 1 or 2 arguments: redirect('/') or redirect('/', { foo: 'bar' }) + let pathType = typeof path + if (typeof status !== 'number' && (pathType === 'undefined' || pathType === 'object')) { + query = path || {} + path = status + pathType = typeof path + status = 302 + } + if (pathType === 'object') { + path = app.router.resolve(path).route.fullPath + } + // "/absolute/route", "./relative/route" or "../relative/route" + if (/(^[.]{1,2}\/)|(^\/(?!\/))/.test(path)) { + app.context.next({ + path, + query, + status + }) + } else { + path = formatUrl(path, query) + if (process.server) { + app.context.next({ + path, + status + }) + } + if (process.client) { + // https://developer.mozilla.org/en-US/docs/Web/API/Location/replace + window.location.replace(path) + + // Throw a redirect error + throw new Error('ERR_REDIRECT') + } + } + } + if (process.server) { + app.context.beforeNuxtRender = fn => context.beforeRenderFns.push(fn) + } + if (process.client) { + app.context.nuxtState = window.__NUXT__ + } + } + + // Dynamic keys + const [currentRouteData, fromRouteData] = await Promise.all([ + getRouteData(context.route), + getRouteData(context.from) + ]) + + if (context.route) { + app.context.route = currentRouteData + } + + if (context.from) { + app.context.from = fromRouteData + } + + app.context.next = context.next + app.context._redirected = false + app.context._errored = false + app.context.isHMR = false + app.context.params = app.context.route.params || {} + app.context.query = app.context.route.query || {} +} + +export function middlewareSeries (promises, appContext) { + if (!promises.length || appContext._redirected || appContext._errored) { + return Promise.resolve() + } + return promisify(promises[0], appContext) + .then(() => { + return middlewareSeries(promises.slice(1), appContext) + }) +} + +export function promisify (fn, context) { + let promise + if (fn.length === 2) { + // fn(context, callback) + promise = new Promise((resolve) => { + fn(context, function (err, data) { + if (err) { + context.error(err) + } + data = data || {} + resolve(data) + }) + }) + } else { + promise = fn(context) + } + + if (promise && promise instanceof Promise && typeof promise.then === 'function') { + return promise + } + return Promise.resolve(promise) +} + +// Imported from vue-router +export function getLocation (base, mode) { + let path = decodeURI(window.location.pathname) + if (mode === 'hash') { + return window.location.hash.replace(/^#\//, '') + } + // To get matched with sanitized router.base add trailing slash + if (base && (path.endsWith('/') ? path : path + '/').startsWith(base)) { + path = path.slice(base.length) + } + return (path || '/') + window.location.search + window.location.hash +} + +// Imported from path-to-regexp + +/** + * Compile a string to a template function for the path. + * + * @param {string} str + * @param {Object=} options + * @return {!function(Object=, Object=)} + */ +export function compile (str, options) { + return tokensToFunction(parse(str, options), options) +} + +export function getQueryDiff (toQuery, fromQuery) { + const diff = {} + const queries = { ...toQuery, ...fromQuery } + for (const k in queries) { + if (String(toQuery[k]) !== String(fromQuery[k])) { + diff[k] = true + } + } + return diff +} + +export function normalizeError (err) { + let message + if (!(err.message || typeof err === 'string')) { + try { + message = JSON.stringify(err, null, 2) + } catch (e) { + message = `[${err.constructor.name}]` + } + } else { + message = err.message || err + } + return { + ...err, + message, + statusCode: (err.statusCode || err.status || (err.response && err.response.status) || 500) + } +} + +/** + * The main path matching regexp utility. + * + * @type {RegExp} + */ +const PATH_REGEXP = new RegExp([ + // Match escaped characters that would otherwise appear in future matches. + // This allows the user to escape special characters that won't transform. + '(\\\\.)', + // Match Express-style parameters and un-named parameters with a prefix + // and optional suffixes. Matches appear as: + // + // "/:test(\\d+)?" => ["/", "test", "\d+", undefined, "?", undefined] + // "/route(\\d+)" => [undefined, undefined, undefined, "\d+", undefined, undefined] + // "/*" => ["/", undefined, undefined, undefined, undefined, "*"] + '([\\/.])?(?:(?:\\:(\\w+)(?:\\(((?:\\\\.|[^\\\\()])+)\\))?|\\(((?:\\\\.|[^\\\\()])+)\\))([+*?])?|(\\*))' +].join('|'), 'g') + +/** + * Parse a string for the raw tokens. + * + * @param {string} str + * @param {Object=} options + * @return {!Array} + */ +function parse (str, options) { + const tokens = [] + let key = 0 + let index = 0 + let path = '' + const defaultDelimiter = (options && options.delimiter) || '/' + let res + + while ((res = PATH_REGEXP.exec(str)) != null) { + const m = res[0] + const escaped = res[1] + const offset = res.index + path += str.slice(index, offset) + index = offset + m.length + + // Ignore already escaped sequences. + if (escaped) { + path += escaped[1] + continue + } + + const next = str[index] + const prefix = res[2] + const name = res[3] + const capture = res[4] + const group = res[5] + const modifier = res[6] + const asterisk = res[7] + + // Push the current path onto the tokens. + if (path) { + tokens.push(path) + path = '' + } + + const partial = prefix != null && next != null && next !== prefix + const repeat = modifier === '+' || modifier === '*' + const optional = modifier === '?' || modifier === '*' + const delimiter = res[2] || defaultDelimiter + const pattern = capture || group + + tokens.push({ + name: name || key++, + prefix: prefix || '', + delimiter, + optional, + repeat, + partial, + asterisk: Boolean(asterisk), + pattern: pattern ? escapeGroup(pattern) : (asterisk ? '.*' : '[^' + escapeString(delimiter) + ']+?') + }) + } + + // Match any characters still remaining. + if (index < str.length) { + path += str.substr(index) + } + + // If the path exists, push it onto the end. + if (path) { + tokens.push(path) + } + + return tokens +} + +/** + * Prettier encoding of URI path segments. + * + * @param {string} + * @return {string} + */ +function encodeURIComponentPretty (str, slashAllowed) { + const re = slashAllowed ? /[?#]/g : /[/?#]/g + return encodeURI(str).replace(re, (c) => { + return '%' + c.charCodeAt(0).toString(16).toUpperCase() + }) +} + +/** + * Encode the asterisk parameter. Similar to `pretty`, but allows slashes. + * + * @param {string} + * @return {string} + */ +function encodeAsterisk (str) { + return encodeURIComponentPretty(str, true) +} + +/** + * Escape a regular expression string. + * + * @param {string} str + * @return {string} + */ +function escapeString (str) { + return str.replace(/([.+*?=^!:${}()[\]|/\\])/g, '\\$1') +} + +/** + * Escape the capturing group by escaping special characters and meaning. + * + * @param {string} group + * @return {string} + */ +function escapeGroup (group) { + return group.replace(/([=!:$/()])/g, '\\$1') +} + +/** + * Expose a method for transforming tokens into the path function. + */ +function tokensToFunction (tokens, options) { + // Compile all the tokens into regexps. + const matches = new Array(tokens.length) + + // Compile all the patterns before compilation. + for (let i = 0; i < tokens.length; i++) { + if (typeof tokens[i] === 'object') { + matches[i] = new RegExp('^(?:' + tokens[i].pattern + ')$', flags(options)) + } + } + + return function (obj, opts) { + let path = '' + const data = obj || {} + const options = opts || {} + const encode = options.pretty ? encodeURIComponentPretty : encodeURIComponent + + for (let i = 0; i < tokens.length; i++) { + const token = tokens[i] + + if (typeof token === 'string') { + path += token + + continue + } + + const value = data[token.name || 'pathMatch'] + let segment + + if (value == null) { + if (token.optional) { + // Prepend partial segment prefixes. + if (token.partial) { + path += token.prefix + } + + continue + } else { + throw new TypeError('Expected "' + token.name + '" to be defined') + } + } + + if (Array.isArray(value)) { + if (!token.repeat) { + throw new TypeError('Expected "' + token.name + '" to not repeat, but received `' + JSON.stringify(value) + '`') + } + + if (value.length === 0) { + if (token.optional) { + continue + } else { + throw new TypeError('Expected "' + token.name + '" to not be empty') + } + } + + for (let j = 0; j < value.length; j++) { + segment = encode(value[j]) + + if (!matches[i].test(segment)) { + throw new TypeError('Expected all "' + token.name + '" to match "' + token.pattern + '", but received `' + JSON.stringify(segment) + '`') + } + + path += (j === 0 ? token.prefix : token.delimiter) + segment + } + + continue + } + + segment = token.asterisk ? encodeAsterisk(value) : encode(value) + + if (!matches[i].test(segment)) { + throw new TypeError('Expected "' + token.name + '" to match "' + token.pattern + '", but received "' + segment + '"') + } + + path += token.prefix + segment + } + + return path + } +} + +/** + * Get the flags for a regexp from the options. + * + * @param {Object} options + * @return {string} + */ +function flags (options) { + return options && options.sensitive ? '' : 'i' +} + +/** + * Format given url, append query to url query string + * + * @param {string} url + * @param {string} query + * @return {string} + */ +function formatUrl (url, query) { + let protocol + const index = url.indexOf('://') + if (index !== -1) { + protocol = url.substring(0, index) + url = url.substring(index + 3) + } else if (url.startsWith('//')) { + url = url.substring(2) + } + + let parts = url.split('/') + let result = (protocol ? protocol + '://' : '//') + parts.shift() + + let path = parts.join('/') + if (path === '' && parts.length === 1) { + result += '/' + } + + let hash + parts = path.split('#') + if (parts.length === 2) { + [path, hash] = parts + } + + result += path ? '/' + path : '' + + if (query && JSON.stringify(query) !== '{}') { + result += (url.split('?').length === 2 ? '&' : '?') + formatQuery(query) + } + result += hash ? '#' + hash : '' + + return result +} + +/** + * Transform data object to query string + * + * @param {object} query + * @return {string} + */ +function formatQuery (query) { + return Object.keys(query).sort().map((key) => { + const val = query[key] + if (val == null) { + return '' + } + if (Array.isArray(val)) { + return val.slice().map(val2 => [key, '=', val2].join('')).join('&') + } + return key + '=' + val + }).filter(Boolean).join('&') +} + +export function addLifecycleHook(vm, hook, fn) { + if (!vm.$options[hook]) { + vm.$options[hook] = [] + } + if (!vm.$options[hook].includes(fn)) { + vm.$options[hook].push(fn) + } +} + +export function urlJoin () { + return [].slice + .call(arguments) + .join('/') + .replace(/\/+/g, '/') + .replace(':/', '://') +} + +export function stripTrailingSlash (path) { + return path.replace(/\/+$/, '') || '/' +} + +export function isSamePath (p1, p2) { + return stripTrailingSlash(p1) === stripTrailingSlash(p2) +} diff --git a/.nuxt/views/app.template.html b/.nuxt/views/app.template.html new file mode 100644 index 0000000..3427d3e --- /dev/null +++ b/.nuxt/views/app.template.html @@ -0,0 +1,9 @@ + + + + {{ HEAD }} + + + {{ APP }} + + diff --git a/.nuxt/views/error.html b/.nuxt/views/error.html new file mode 100644 index 0000000..efd3228 --- /dev/null +++ b/.nuxt/views/error.html @@ -0,0 +1,23 @@ + + + +Server error + + + + + +
+
+ +
Server error
+
An error occurred in the application and your page could not be served. If you are the application owner, check your logs for details.
+
+ +
+ + diff --git a/components/footer.vue b/components/footer.vue index 314905b..9cf665b 100644 --- a/components/footer.vue +++ b/components/footer.vue @@ -26,7 +26,7 @@ -->