diff --git a/README.md b/README.md index fca01f8..d8905b4 100644 --- a/README.md +++ b/README.md @@ -156,6 +156,27 @@ The content should look as follows: } ``` +### Create different Radars +To create different radars with one set of blips put a `radars` entry in your frontmatter: +```yaml +--- +title: Item +ring: adopt +quadrant: tools +radars: [radar-1, radar-2] +--- +``` + +Then, to select the blips put a `radar` entry in the `config.json` for generating the site: +```json +{ + "radar": "radar-1", + "quadrants": { + ... +``` + +This will only add blips with the defined radar into the output. + ### Change the index.html To change the index.html, create a public folder in your application and put your `index.html` in it. diff --git a/dist_scripts/scripts/generateJson/radar.js b/dist_scripts/scripts/generateJson/radar.js index 22e983c..132f7f6 100644 --- a/dist_scripts/scripts/generateJson/radar.js +++ b/dist_scripts/scripts/generateJson/radar.js @@ -97,7 +97,7 @@ marked_1.marked.setOptions({ highlight: function (code) { return highlight_js_1.default.highlightAuto(code).value; }, }); var createRadar = function () { return __awaiter(void 0, void 0, void 0, function () { - var fileNames, revisions, allReleases, items, flaggedItems; + var fileNames, revisions, filterdRevisions, allReleases, items, flaggedItems; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, (0, file_1.getAllMarkdownFiles)((0, file_1.radarPath)())]; @@ -106,8 +106,9 @@ var createRadar = function () { return __awaiter(void 0, void 0, void 0, functio return [4 /*yield*/, createRevisionsFromFiles(fileNames)]; case 2: revisions = _a.sent(); - allReleases = getAllReleases(revisions); - items = createItems(revisions); + filterdRevisions = revisions.filter(function (r) { return r !== undefined; }); + allReleases = getAllReleases(filterdRevisions); + items = createItems(filterdRevisions); flaggedItems = flagItem(items, allReleases); items.forEach(function (item) { return checkAttributes(item.name, item); }); return [2 /*return*/, { @@ -119,7 +120,7 @@ var createRadar = function () { return __awaiter(void 0, void 0, void 0, functio }); }; exports.createRadar = createRadar; var checkAttributes = function (fileName, attributes) { - var rawConf = (0, fs_1.readFileSync)(path.resolve(paths_1.appBuild, 'config.json'), 'utf-8'); + var rawConf = fs_1.readFileSync(path.resolve(paths_1.appBuild, "config.json"), "utf-8"); var config = JSON.parse(rawConf); if (!config.rings.includes(attributes.ring)) { throw new Error("Error: ".concat(fileName, " has an illegal value for 'ring' - must be one of ").concat(config.rings)); @@ -128,27 +129,24 @@ var checkAttributes = function (fileName, attributes) { if (!quadrants.includes(attributes.quadrant)) { throw new Error("Error: ".concat(fileName, " has an illegal value for 'quadrant' - must be one of ").concat(quadrants)); } + if (config.radar && attributes.radars) { + if (!attributes.radars.includes(config.radar)) { + return undefined; + } + } return attributes; }; var createRevisionsFromFiles = function (fileNames) { var publicUrl = process.env.PUBLIC_URL; return Promise.all(fileNames.map(function (fileName) { - return new Promise(function (resolve, reject) { - (0, fs_extra_1.readFile)(fileName, "utf8", function (err, data) { return __awaiter(void 0, void 0, void 0, function () { - var fm, html; - return __generator(this, function (_a) { - if (err) { - reject(err); - } - else { - fm = (0, front_matter_1.default)(data); - html = (0, marked_1.marked)(fm.body.replace(/\]\(\//g, "](".concat(publicUrl, "/"))); - html = html.replace(/a href="http/g, 'a target="_blank" rel="noopener noreferrer" href="http'); - resolve(__assign(__assign(__assign({}, itemInfoFromFilename(fileName)), fm.attributes), { fileName: fileName, body: html })); - } - return [2 /*return*/]; - }); - }); }); + return fs_extra_1.readFile(fileName, "utf8").then(function (data) { + var fm = front_matter_1.default(data); + var html = marked_1.marked(fm.body.replace(/\]\(\//g, "](" + publicUrl + "/")); + html = html.replace(/a href="http/g, 'a target="_blank" rel="noopener noreferrer" href="http'); + var attributes = checkAttributes(fileName, fm.attributes); + if (attributes) { + return __assign(__assign(__assign({}, itemInfoFromFilename(fileName)), attributes), { fileName: fileName, body: html }); + } }); })); }; diff --git a/scripts/generateJson/radar.ts b/scripts/generateJson/radar.ts index 2053a3f..f7ec0dd 100644 --- a/scripts/generateJson/radar.ts +++ b/scripts/generateJson/radar.ts @@ -18,9 +18,10 @@ marked.setOptions({ export const createRadar = async (): Promise => { const fileNames = await getAllMarkdownFiles(radarPath()); - const revisions = await createRevisionsFromFiles(fileNames); - const allReleases = getAllReleases(revisions); - const items = createItems(revisions); + const revisions: (Revision|undefined)[] = await createRevisionsFromFiles(fileNames); + const filterdRevisions : Revision[] = revisions.filter(r => r !== undefined) as Revision[]; + const allReleases = getAllReleases(filterdRevisions); + const items = createItems(filterdRevisions); const flaggedItems = flagItem(items, allReleases); items.forEach(item => checkAttributes(item.name, item)) @@ -32,7 +33,7 @@ export const createRadar = async (): Promise => { }; const checkAttributes = (fileName: string, attributes: FMAttributes) => { - const rawConf = readFileSync(path.resolve(appBuild, 'config.json'), 'utf-8'); + const rawConf = readFileSync(path.resolve(appBuild, "config.json"), "utf-8"); const config = JSON.parse(rawConf); if (!config.rings.includes(attributes.ring)) { @@ -48,6 +49,12 @@ const checkAttributes = (fileName: string, attributes: FMAttributes) => { ); } + if (config.radar && attributes.radars) { + if (!attributes.radars.includes(config.radar)) { + return undefined; + } + } + return attributes; }; @@ -56,28 +63,22 @@ const createRevisionsFromFiles = (fileNames: string[]) => { return Promise.all( fileNames.map( (fileName) => - new Promise((resolve, reject) => { - readFile(fileName, "utf8", async (err, data) => { - if (err) { - reject(err); - } else { - const fm = frontMatter(data); - // add target attribute to external links - // todo: check path - let html = marked(fm.body.replace(/\]\(\//g, `](${publicUrl}/`)); - html = html.replace( - /a href="http/g, - 'a target="_blank" rel="noopener noreferrer" href="http' - ); - - resolve({ - ...itemInfoFromFilename(fileName), - ...fm.attributes, - fileName, - body: html, - } as Revision); - } - }); + readFile(fileName, "utf8").then(data => { + const fm = frontMatter(data); + let html = marked(fm.body.replace(/\]\(\//g, `](${publicUrl}/`)); + html = html.replace( + /a href="http/g, + 'a target="_blank" rel="noopener noreferrer" href="http' + ); + const attributes = checkAttributes(fileName, fm.attributes); + if (attributes) { + return { + ...itemInfoFromFilename(fileName), + ...attributes, + fileName, + body: html, + } as Revision; + } }) ) ); diff --git a/src/model.ts b/src/model.ts index 25eced1..de4ec1d 100644 --- a/src/model.ts +++ b/src/model.ts @@ -10,6 +10,7 @@ export type ItemAttributes = { quadrant: string; title: string; featured?: boolean; + radars?: string[]; }; export enum FlagType {