Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
v8tenko committed Nov 2, 2024
1 parent 8ebd341 commit b9d5d00
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/transform/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {bold} from 'chalk';
import {log} from './log';
import liquidSnippet from './liquid';
import initMarkdownIt from './md';
import {collect as collectUsedCSP} from './plugins/csp';

function applyLiquid(input: string, options: OptionsType) {
const {
Expand All @@ -28,7 +29,7 @@ function handleError(error: unknown, path?: string): never {

function emitResult(html: string, env: EnvType): OutputType {
return {
result: {...env, html},
result: {...env, html, csp: collectUsedCSP()},
logs: log.get(),
};
}
Expand Down
16 changes: 11 additions & 5 deletions src/transform/plugins/csp.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const csp: Record<string, string[]> = {};
let csp: Record<string, string[]> = {};

export type CustomCSP = Record<string, string | string[]>;

Expand All @@ -10,16 +10,22 @@ const requestCSP = (policy: CustomCSP) => {

const flat = Array.isArray(content) ? content : [content];

flat.forEach((value) => {
for (const value of flat) {
if (csp[field].includes(value)) {
return;
continue;
}

csp[field].push(value);
});
}
}
};

const collect = () => csp;
const collect = () => {
const usedCSP = {...csp};

csp = {};

return usedCSP;
};

export {requestCSP, collect};

0 comments on commit b9d5d00

Please sign in to comment.