Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
Vue.nextTick(() => {
// console.log('Keys ', Object.keys(guess()))
const predictions = Object.keys(guess()).sort((a, b) => a.probability - b.probability)
// console.log('Predictions ', predictions)
predictions.forEach(path => {
// console.log('Path: ', path)
router.getMatchedComponents(path).forEach(Component => {
if (typeof Component === 'function' && !Component.__prefetched) {
try {
Component()
Component.__prefetched = true
} catch (e) {}
}
})
})
})
}
render() {
// eslint-disable-next-line
const matches = guess({ path: this.props.location.pathname })
Object.keys(matches).forEach(match => fetchArticle(match.slice(6)))
let toRender = ``
const articleName = this.props.location.pathname.slice(6)
if (this.props.location.pathname === `/_/`) {
return <div>hi</div>
}
if (this.props.data.wikipediaArticle) {
toRender = this.props.data.wikipediaArticle.rendered
} else if (htmlCache[articleName]) {
toRender = htmlCache[articleName]
} else if (
!this.props.data.wikipediaArticle &&
!promiseCache[articleName]
) {
// eslint-disable-next-line
fetchArticle(articleName).then(text => {
const colorLinks = () => {
const guesses = guess({
path: window.location.pathname
});
[].slice.call(document.querySelectorAll(`a`)).forEach(n => n.classList.add('prefetch-priority-0'));
let all = Object.keys(guesses).map(key => guesses[key]);
all = all.filter((p, idx) => all.indexOf(p) === idx); //.sort((a, b) => a - b);
Object.keys(guesses).forEach(c => {
const probability = guesses[c];
let totalBigger = 0;
for (let i = 0; i < all.length; i += 1) {
if (all[i] > probability) {
totalBigger += 1;
}
}
const third = Math.round(all.length / 3);
let color = 1;
if (totalBigger < third) {
const layout = ({ router, children, title = '🔮 Next.js + Guess.js' }) => {
let predictions = [];
if (typeof window !== 'undefined') {
predictions = Object.keys(guess()).sort((a, b) => a.length - b.length);
predictions.forEach(p => router.prefetch(p));
}
return (
<div>
<title>{title}</title>
<header>
<nav>
<span></span></nav></header></div>
webpack: function(config, { isServer }) {
if (isServer) return config;
config.plugins.push(
new GuessPlugin({
debug: true,
reportProvider() {
return Promise.resolve(JSON.parse(require('fs').readFileSync('./routes.json')));
},
runtime: {
delegate: true
}
})
);
return config;
}
};
this.extendBuild((config, ctx) => {
if (!ctx.isDev && ctx.isClient) {
config.plugins.push(new GuessPlugin(options))
}
})
}