Skip to content

Commit

Permalink
Modify preview
Browse files Browse the repository at this point in the history
  • Loading branch information
vn7n24fzkq committed Sep 3, 2020
1 parent 7705dd2 commit 8896f32
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 21 deletions.
30 changes: 17 additions & 13 deletions src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ const createProfileDetailsCard = async function (username) {
contributionsData,
theme
);
//output to folder
writeSVG(themeName, "profile-details", svgString);
//output to folder, use 0- prefix for sort in preview
writeSVG(themeName, "0-profile-details", svgString);
}
};

Expand All @@ -115,9 +115,13 @@ const createReposPerLanguageCard = async function (username) {

for (let themeName in Themes) {
let theme = Themes[themeName];
let svgString = createDonutChartCard("Repos per Language (top 5)", langData, theme);
//output to folder
writeSVG(themeName, "repos-per-language", svgString);
let svgString = createDonutChartCard(
"Repos per Language (top 5)",
langData,
theme
);
//output to folder, use 1- prefix for sort in preview
writeSVG(themeName, "1-repos-per-language", svgString);
}
};

Expand Down Expand Up @@ -160,8 +164,8 @@ const createCommitsPerLanguageCard = async function (username) {
langData,
theme
);
//output to folder
writeSVG(themeName, "most-commit-language", svgString);
//output to folder, use 2- prefix for sort in preview
writeSVG(themeName, "2-most-commit-language", svgString);
}
};

Expand Down Expand Up @@ -241,13 +245,13 @@ const main = async () => {
} catch (error) {
core.error(`Error when creating CommitsPerLanguageCard \n${error}`);
}
try {
core.info(`Createing preview markdown...`);
await generatePreviewMarkdown(isInGithubAction);
} catch (error) {
core.error(`Error when creating preview markdown \n${error}`);
}
if (isInGithubAction) {
try {
core.info(`Createing preview markdown...`);
await generatePreviewMarkdown();
} catch (error) {
core.error(`Error when creating preview markdown \n${error}`);
}
core.info(`Commit file...`);
await commitFile();
}
Expand Down
20 changes: 12 additions & 8 deletions src/utils/file-writer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ const Themes = require("../const/theme");
const GITHUB_REPOSITORY = process.env.GITHUB_REPOSITORY;

// If neither a branch or tag is available for the event type, the variable will not exist. https://docs.github.com/en/actions/configuring-and-managing-workflows/using-environment-variables
const GITHUB_BRANCH = process.env.GITHUB_REF == undefined ? "master":process.env.GITHUB_REF.split("/").pop();
const GITHUB_BRANCH =
process.env.GITHUB_REF == undefined
? "master"
: process.env.GITHUB_REF.split("/").pop();

const writeSVG = function (folder, filename, svgString) {
const targetFolder = `${outputPath}${folder}/`;
Expand All @@ -25,29 +28,30 @@ function getAllFileInFolder(folder) {
return files;
}

const generatePreviewMarkdown = function (pro) {
const generatePreviewMarkdown = function (isInGithubAction) {
let targetFolder = `${outputPath}`;
let readmeContent = "";
readmeContent +=
`
let urlPrefix = isInGithubAction
? `https://raw.githubusercontent.com/${GITHUB_REPOSITORY}/${GITHUB_BRANCH}/profile-summary-card-output`
: `.`;
readmeContent += `
# Preview Cards
Here are all cards with themes.
`;

for (let themeName in Themes) {
readmeContent +=
`
readmeContent += `
### ${themeName}
`;
for (let file of getAllFileInFolder(targetFolder + themeName)) {
readmeContent += `
\`\`\`
![](https://raw.githubusercontent.com/${GITHUB_REPOSITORY}/${GITHUB_BRANCH}/profile-summary-card-output/${themeName}/${file})
![](${urlPrefix}/${themeName}/${file})
\`\`\`
![](https://raw.githubusercontent.com/${GITHUB_REPOSITORY}/${GITHUB_BRANCH}/profile-summary-card-output/${themeName}/${file})
![](${urlPrefix}/${themeName}/${file})
`;
}
Expand Down

0 comments on commit 8896f32

Please sign in to comment.