feat(core): add insights output (#575)
This commit is contained in:
@@ -45,6 +45,10 @@ export default async function metrics({login, q}, {graphql, rest, plugins, conf,
|
||||
if (conf.settings["debug.headless"])
|
||||
imports.puppeteer.headless = false
|
||||
|
||||
//Metrics insights
|
||||
if (convert === "insights")
|
||||
return metrics.insights.output({login, imports, conf}, {graphql, rest, Plugins, Templates})
|
||||
|
||||
//Partial parts
|
||||
{
|
||||
data.partials = new Set([
|
||||
@@ -209,3 +213,65 @@ export default async function metrics({login, q}, {graphql, rest, plugins, conf,
|
||||
throw error
|
||||
}
|
||||
}
|
||||
|
||||
//Metrics insights
|
||||
metrics.insights = async function({login}, {graphql, rest, conf}, {Plugins, Templates}) {
|
||||
const q = {
|
||||
template:"classic",
|
||||
achievements:true,
|
||||
"achievements.threshold":"X",
|
||||
isocalendar:true,
|
||||
"isocalendar.duration":"full-year",
|
||||
languages:true,
|
||||
"languages.limit":0,
|
||||
activity:true,
|
||||
"activity.limit":100,
|
||||
"activity.days":0,
|
||||
notable:true,
|
||||
followup:true,
|
||||
"followup.sections":"repositories, user",
|
||||
habits:true,
|
||||
"habits.from":100,
|
||||
"habits.days":7,
|
||||
"habits.facts":false,
|
||||
"habits.charts":true,
|
||||
introduction:true
|
||||
}
|
||||
const plugins = {achievements:{enabled:true}, isocalendar:{enabled:true}, languages:{enabled:true, extras:false}, activity:{enabled:true, markdown:"extended"}, notable:{enabled:true}, followup:{enabled:true}, habits:{enabled:true, extras:false}, introduction:{enabled:true}}
|
||||
return metrics({login, q}, {graphql, rest, plugins, conf, convert:"json"}, {Plugins, Templates})
|
||||
}
|
||||
|
||||
//Metrics insights static render
|
||||
metrics.insights.output = async function ({login, imports, conf}, {graphql, rest, Plugins, Templates}) {
|
||||
//Server
|
||||
console.debug(`metrics/compute/${login} > insights`)
|
||||
const server = `http://localhost:${conf.settings.port}`
|
||||
console.debug(`metrics/compute/${login} > insights > server on port ${conf.settings.port}`)
|
||||
|
||||
//Data processing
|
||||
const browser = await imports.puppeteer.launch()
|
||||
const page = await browser.newPage()
|
||||
console.debug(`metrics/compute/${login} > insights > generating data`)
|
||||
const json = JSON.stringify(await metrics.insights({login}, {graphql, rest, conf}, {Plugins, Templates}))
|
||||
await page.goto(`${server}/about/${login}?embed=1&localstorage=1`)
|
||||
await page.evaluate(async json => localStorage.setItem("local.metrics", json), json) //eslint-disable-line no-undef
|
||||
await page.goto(`${server}/about/${login}?embed=1&localstorage=1`)
|
||||
await page.waitForSelector(".container .user", {timeout:10*60*1000})
|
||||
|
||||
//Rendering
|
||||
console.debug(`metrics/compute/${login} > insights > rendering data`)
|
||||
const rendered = `
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Metrics insights: ${login}</title>
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
</head>
|
||||
<body>
|
||||
${await page.evaluate(() => document.querySelector("main").outerHTML)}
|
||||
${(await Promise.all([".css/style.vars.css", ".css/style.css", "about/.statics/style.css"].map(path => utils.axios.get(`${server}/${path}`)))).map(({data:style}) => `<style>${style}</style>`).join("\n")}
|
||||
</body>
|
||||
</html>`
|
||||
await browser.close()
|
||||
return {mime:"text/html", rendered}
|
||||
}
|
||||
@@ -30,7 +30,7 @@ export default async function({log = true, nosettings = false, community = {}} =
|
||||
authenticated:null,
|
||||
templates:{},
|
||||
queries:{},
|
||||
settings:{},
|
||||
settings:{port:3000},
|
||||
metadata:{},
|
||||
paths:{
|
||||
statics:__statics,
|
||||
|
||||
Reference in New Issue
Block a user