From 0282c5cf53794f2299e506dc0e52468dd21427d3 Mon Sep 17 00:00:00 2001 From: Igor Korovchenko Date: Tue, 5 Mar 2024 14:11:24 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=B5=D0=BB=D0=B0=D0=B5=D1=82=20=D0=BE?= =?UTF-8?q?=D0=B1=D0=BD=D0=BE=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=B8?= =?UTF-8?q?=D0=BD=D1=84=D0=BE=D1=80=D0=BC=D0=B0=D1=86=D0=B8=D0=B8=20=D0=BE?= =?UTF-8?q?=20=D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D0=BE=D0=B2=D0=B0=D1=82=D0=B5?= =?UTF-8?q?=D0=BB=D0=B5=20=D1=82=D0=BE=D0=BB=D1=8C=D0=BA=D0=BE=20=D0=B4?= =?UTF-8?q?=D0=BB=D1=8F=20=D0=BF=D1=80=D0=BE=D0=B4.=20=D1=81=D0=B1=D0=BE?= =?UTF-8?q?=D1=80=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/views.11tydata.js | 59 +++++++++++++++++++++---------------- 1 file changed, 34 insertions(+), 25 deletions(-) diff --git a/src/views/views.11tydata.js b/src/views/views.11tydata.js index b5c93c2f5..7fcf7c014 100644 --- a/src/views/views.11tydata.js +++ b/src/views/views.11tydata.js @@ -13,6 +13,7 @@ const { } = require('../libs/github-contribution-service/github-contribution-service') const { contentRepLink } = require('../../config/constants') const { setPath } = require('../libs/collection-helpers/set-path') +const { isProdEnv } = require('../../config/env.js') function isExternalURL(url) { return url.startsWith('http://') || url.startsWith('https://') || url.startsWith('//') @@ -148,7 +149,7 @@ module.exports = { practicesByPerson[personId][category] = [] } practicesByPerson[personId][category].push( - collections[category].find((article) => article.filePathStem === `/${category}/${articleId}/index`) + collections[category].find((article) => article.filePathStem === `/${category}/${articleId}/index`), ) }) return practicesByPerson @@ -191,7 +192,7 @@ module.exports = { collections.question.filter((question) => { return question.fileSlug === questionId })[0].data.related, - collections + collections, ) if (related) { @@ -216,7 +217,7 @@ module.exports = { for (const questionKey in answersByQuestion) { for (const personKey in answersByQuestion[questionKey]) { const answersOfPersonByQuestion = allAnswers.filter((a) => - a.filePathStem.startsWith(`/interviews/${questionKey}/answers/${personKey}`) + a.filePathStem.startsWith(`/interviews/${questionKey}/answers/${personKey}`), ) if (!answersByPerson[personKey]) { answersByPerson[personKey] = {} @@ -244,7 +245,7 @@ module.exports = { } return true } - }) + }), ) } } @@ -315,25 +316,33 @@ module.exports = { }) const authorsNames = filteredAuthors.map((author) => author.fileSlug) - const contributionStat = await getAuthorsContributionWithCache({ - authors: authorsNames, - // 'https://github.com/doka-guide/content' -> 'doka-guide/content' - repo: new URL(contentRepLink).pathname.replace(/^\//, ''), - }) - const contributorExists = await getAuthorsExistsWithCache({ - authors: authorsNames, - }) - const contributorIDs = await getAuthorsIDsWithCache({ - authors: authorsNames.filter((a) => (contributorExists[a] ? contributorExists[a].userCount > 0 : false)), - // 'https://github.com/doka-guide/content' -> 'doka-guide/content' - repo: new URL(contentRepLink).pathname.replace(/^\//, ''), - }) - const contributionActions = await getActionsInRepoWithCache({ - authors: authorsNames, - authorIDs: contributorIDs, - // 'https://github.com/doka-guide/content' -> 'doka-guide/content' - repo: new URL(contentRepLink).pathname.replace(/^\//, ''), - }) + + let contributionStat = undefined + let contributorExists = undefined + let contributorIDs = undefined + let contributionActions = undefined + + if (isProdEnv) { + contributionStat = await getAuthorsContributionWithCache({ + authors: authorsNames, + // 'https://github.com/doka-guide/content' -> 'doka-guide/content' + repo: new URL(contentRepLink).pathname.replace(/^\//, ''), + }) + contributorExists = await getAuthorsExistsWithCache({ + authors: authorsNames, + }) + contributorIDs = await getAuthorsIDsWithCache({ + authors: authorsNames.filter((a) => (contributorExists[a] ? contributorExists[a].userCount > 0 : false)), + // 'https://github.com/doka-guide/content' -> 'doka-guide/content' + repo: new URL(contentRepLink).pathname.replace(/^\//, ''), + }) + contributionActions = await getActionsInRepoWithCache({ + authors: authorsNames, + authorIDs: contributorIDs, + // 'https://github.com/doka-guide/content' -> 'doka-guide/content' + repo: new URL(contentRepLink).pathname.replace(/^\//, ''), + }) + } return filteredAuthors .map((person) => { @@ -426,8 +435,8 @@ module.exports = { totalArticles, totalPractices, totalAnswers, - contributionStat: contributionStat[personId], - contributionActions: contributionActions[personId], + contributionStat: contributionStat ? contributionStat[personId] : null, + contributionActions: contributionActions ? contributionActions[personId] : null, } }) .sort((person1, person2) => person2.totalArticles - person1.totalArticles)