mirror of
https://github.com/ipfs/ipfs-blog.git
synced 2026-04-30 10:33:57 +02:00
chore: setup speedcurve script
This commit is contained in:
@@ -3,6 +3,7 @@ const { reverse, sortBy } = require('lodash')
|
||||
// configure this to an absolute url to enable a generated sitemap & blog RSS feeds
|
||||
const CANONICAL_BASE = process.env.CANONICAL_BASE || ''
|
||||
const IPFS_DEPLOY = process.env.IPFS_DEPLOY === 'true' || false
|
||||
const SPEEDCURVE_ID = process.env.SPEEDCURVE_ID || ''
|
||||
|
||||
const themeConfigDefaults = {
|
||||
dateFormat: 'DD MMMM YYYY',
|
||||
@@ -134,6 +135,7 @@ module.exports = {
|
||||
},
|
||||
},
|
||||
plugins: [
|
||||
[require('./plugins/vuepress-plugin-speedcurve'), { id: SPEEDCURVE_ID }],
|
||||
['@vuepress/last-updated'],
|
||||
[
|
||||
'vuepress-plugin-clean-urls',
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
'use strict'
|
||||
|
||||
/* global SPEEDCURVE_ID */
|
||||
|
||||
module.exports = () => {
|
||||
if (
|
||||
process.env.NODE_ENV === 'production' &&
|
||||
SPEEDCURVE_ID &&
|
||||
typeof window !== 'undefined'
|
||||
) {
|
||||
;(function () {
|
||||
const customScriptCode = `LUX=(function(){var a=("undefined"!==typeof(LUX)&&"undefined"!==typeof(LUX.gaMarks)?LUX.gaMarks:[]);var d=("undefined"!==typeof(LUX)&&"undefined"!==typeof(LUX.gaMeasures)?LUX.gaMeasures:[]);var j="LUX_start";var k=window.performance;var l=("undefined"!==typeof(LUX)&&LUX.ns?LUX.ns:(Date.now?Date.now():+(new Date())));if(k&&k.timing&&k.timing.navigationStart){l=k.timing.navigationStart}function f(){if(k&&k.now){return k.now()}var o=Date.now?Date.now():+(new Date());return o-l}function b(n){if(k){if(k.mark){return k.mark(n)}else{if(k.webkitMark){return k.webkitMark(n)}}}a.push({name:n,entryType:"mark",startTime:f(),duration:0});return}function m(p,t,n){if("undefined"===typeof(t)&&h(j)){t=j}if(k){if(k.measure){if(t){if(n){return k.measure(p,t,n)}else{return k.measure(p,t)}}else{return k.measure(p)}}else{if(k.webkitMeasure){return k.webkitMeasure(p,t,n)}}}var r=0,o=f();if(t){var s=h(t);if(s){r=s.startTime}else{if(k&&k.timing&&k.timing[t]){r=k.timing[t]-k.timing.navigationStart}else{return}}}if(n){var q=h(n);if(q){o=q.startTime}else{if(k&&k.timing&&k.timing[n]){o=k.timing[n]-k.timing.navigationStart}else{return}}}d.push({name:p,entryType:"measure",startTime:r,duration:(o-r)});return}function h(n){return c(n,g())}function c(p,o){for(i=o.length-1;i>=0;i--){var n=o[i];if(p===n.name){return n}}return undefined}function g(){if(k){if(k.getEntriesByType){return k.getEntriesByType("mark")}else{if(k.webkitGetEntriesByType){return k.webkitGetEntriesByType("mark")}}}return a}return{mark:b,measure:m,gaMarks:a,gaMeasures:d}})();LUX.ns=(Date.now?Date.now():+(new Date()));LUX.ac=[];LUX.cmd=function(a){LUX.ac.push(a)};LUX.init=function(){LUX.cmd(["init"])};LUX.send=function(){LUX.cmd(["send"])};LUX.addData=function(a,b){LUX.cmd(["addData",a,b])};LUX_ae=[];window.addEventListener("error",function(a){LUX_ae.push(a)});LUX_al=[];if("function"===typeof(PerformanceObserver)&&"function"===typeof(PerformanceLongTaskTiming)){var LongTaskObserver=new PerformanceObserver(function(c){var b=c.getEntries();for(var a=0;a<b.length;a++){var d=b[a];LUX_al.push(d)}});try{LongTaskObserver.observe({type:["longtask"]})}catch(e){}};`
|
||||
const src = `https://cdn.speedcurve.com/js/lux.js?id=${SPEEDCURVE_ID}`
|
||||
|
||||
const remoteScript = document.createElement('script')
|
||||
remoteScript.src = src
|
||||
remoteScript.type = 'text/javascript'
|
||||
remoteScript.async = true
|
||||
remoteScript.defer = true
|
||||
remoteScript.crossOrigin = 'anonymous'
|
||||
|
||||
const script = document.createElement('script')
|
||||
script.innerHTML = customScriptCode
|
||||
|
||||
document.head.prepend(script)
|
||||
document.head.insertBefore(remoteScript, script.nextSibling)
|
||||
})()
|
||||
}
|
||||
}
|
||||
11
src/.vuepress/plugins/vuepress-plugin-speedcurve/index.js
Normal file
11
src/.vuepress/plugins/vuepress-plugin-speedcurve/index.js
Normal file
@@ -0,0 +1,11 @@
|
||||
const path = require('path')
|
||||
|
||||
module.exports = (params = {}) => ({
|
||||
name: 'vuepress-plugin-speedcurve',
|
||||
define() {
|
||||
const id = params.id
|
||||
|
||||
return { SPEEDCURVE_ID: id || false }
|
||||
},
|
||||
enhanceAppFiles: path.resolve(__dirname, 'enhanceAppFiles.js'),
|
||||
})
|
||||
Reference in New Issue
Block a user