Skip to content

Commit

Permalink
feat: add url to HTML report from cli dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
ayushnirwal committed May 8, 2024
1 parent 98c827b commit 3e5481b
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ const Layout = ({
return;
}

generateSiteMapReportandDownload(completeJson);
generateSiteMapReportandDownload(completeJson, '');
},
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ import type { CompleteJson } from '@ps-analysis-tool/common';
*/
import { createZip, getFolderName, generateSiemapHTMLFile } from './utils';

const generateSiteMapReportandDownload = async (JSONReport: CompleteJson[]) => {
const generateSiteMapReportandDownload = async (
JSONReport: CompleteJson[],
sitemapUrl: string
) => {
if (!JSONReport.length) {
return;
}
Expand All @@ -48,10 +51,10 @@ const generateSiteMapReportandDownload = async (JSONReport: CompleteJson[]) => {
return;
}

createZip(data, zipFolder);
createZip(data, zipFolder, data.pageUrl);
});

const report = generateSiemapHTMLFile(JSONReport);
const report = generateSiemapHTMLFile(JSONReport, sitemapUrl);

zip.file('report.html', report);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const generateSiteReportandDownload = async (
return;
}

createZip(siteAnalysisData, zipFolder);
createZip(siteAnalysisData, zipFolder, selectedPageUrl || '');

const content = await zip.generateAsync({ type: 'blob' });
saveAs(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,12 @@ const generateCSVFiles = (data: CompleteJson) => {

/**
*
* @param analysisData
* @param analysisData Anaylsis Data
* @param url URL
* @param siteURL
* @returns Object Report object required to make HTML report
*/
function generateReportObject(analysisData: CompleteJson) {
function generateReportObject(analysisData: CompleteJson, siteURL: string) {
const tabCookies = reshapeCookies(
extractCookies(analysisData.cookieData, analysisData.pageUrl)
);
Expand Down Expand Up @@ -128,15 +130,20 @@ function generateReportObject(analysisData: CompleteJson) {
frameStateCreator,
exemptedCookiesDataMapping,
showBlockedCategory: true,
url: siteURL,
};
}

/**
*
* @param analysisData
* @param analysisData Analysis Data
* @param sitemapURL URL for the sitemap
* @returns Object Report object required to make HTML report
*/
function generateSitemapReportObject(analysisData: CompleteJson[]) {
function generateSitemapReportObject(
analysisData: CompleteJson[],
sitemapURL: string
) {
const tabCookies = reshapeCookies(
extractReportData(analysisData).landingPageCookies
);
Expand Down Expand Up @@ -202,18 +209,19 @@ function generateSitemapReportObject(analysisData: CompleteJson[]) {
exemptedCookiesDataMapping,
showFramesSection: false,
showBlockedCategory: true,
url: sitemapURL,
};
}

const generateHTMLFile = async (analysisData: CompleteJson) => {
const generateHTMLFile = async (analysisData: CompleteJson, url: string) => {
const htmlText = await (await fetch('./report/index.html')).text();
const parser = new DOMParser();
const reportDom = parser.parseFromString(htmlText, 'text/html');

// Injections
const script = reportDom.createElement('script');

const reportData = generateReportObject(analysisData);
const reportData = generateReportObject(analysisData, url);

const code = `window.PSAT_DATA = ${JSON.stringify(reportData)}`;

Expand All @@ -226,15 +234,18 @@ const generateHTMLFile = async (analysisData: CompleteJson) => {
return html;
};

export const generateSiemapHTMLFile = async (analysisData: CompleteJson[]) => {
export const generateSiemapHTMLFile = async (
analysisData: CompleteJson[],
sitemapURL: string
) => {
const htmlText = await (await fetch('./report/index.html')).text();
const parser = new DOMParser();
const reportDom = parser.parseFromString(htmlText, 'text/html');

// Injections
const script = reportDom.createElement('script');

const reportData = generateSitemapReportObject(analysisData);
const reportData = generateSitemapReportObject(analysisData, sitemapURL);

const code = `window.PSAT_DATA = ${JSON.stringify(reportData)}`;

Expand All @@ -247,15 +258,19 @@ export const generateSiemapHTMLFile = async (analysisData: CompleteJson[]) => {
return html;
};

export const createZip = (analysisData: CompleteJson, zipObject: JSZip) => {
export const createZip = (
analysisData: CompleteJson,
zipObject: JSZip,
url: string
) => {
const {
allCookiesCSV,
technologyDataCSV,
cookiesWithIssuesDataCSV,
summaryDataCSV,
} = generateCSVFiles(analysisData);

const file = generateHTMLFile(analysisData);
const file = generateHTMLFile(analysisData, url);

zipObject.file('cookies.csv', allCookiesCSV);
if (technologyDataCSV) {
Expand Down

0 comments on commit 3e5481b

Please sign in to comment.