Enable multiple radars
This commit is contained in:
committed by
Bastian
parent
b30f7fe5d4
commit
faadd8681d
21
README.md
21
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
|
### Change the index.html
|
||||||
To change the index.html, create a public folder in your application and put your `index.html` in it.
|
To change the index.html, create a public folder in your application and put your `index.html` in it.
|
||||||
|
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ marked_1.marked.setOptions({
|
|||||||
highlight: function (code) { return highlight_js_1.default.highlightAuto(code).value; },
|
highlight: function (code) { return highlight_js_1.default.highlightAuto(code).value; },
|
||||||
});
|
});
|
||||||
var createRadar = function () { return __awaiter(void 0, void 0, void 0, function () {
|
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) {
|
return __generator(this, function (_a) {
|
||||||
switch (_a.label) {
|
switch (_a.label) {
|
||||||
case 0: return [4 /*yield*/, (0, file_1.getAllMarkdownFiles)((0, file_1.radarPath)())];
|
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)];
|
return [4 /*yield*/, createRevisionsFromFiles(fileNames)];
|
||||||
case 2:
|
case 2:
|
||||||
revisions = _a.sent();
|
revisions = _a.sent();
|
||||||
allReleases = getAllReleases(revisions);
|
filterdRevisions = revisions.filter(function (r) { return r !== undefined; });
|
||||||
items = createItems(revisions);
|
allReleases = getAllReleases(filterdRevisions);
|
||||||
|
items = createItems(filterdRevisions);
|
||||||
flaggedItems = flagItem(items, allReleases);
|
flaggedItems = flagItem(items, allReleases);
|
||||||
items.forEach(function (item) { return checkAttributes(item.name, item); });
|
items.forEach(function (item) { return checkAttributes(item.name, item); });
|
||||||
return [2 /*return*/, {
|
return [2 /*return*/, {
|
||||||
@@ -119,7 +120,7 @@ var createRadar = function () { return __awaiter(void 0, void 0, void 0, functio
|
|||||||
}); };
|
}); };
|
||||||
exports.createRadar = createRadar;
|
exports.createRadar = createRadar;
|
||||||
var checkAttributes = function (fileName, attributes) {
|
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);
|
var config = JSON.parse(rawConf);
|
||||||
if (!config.rings.includes(attributes.ring)) {
|
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));
|
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)) {
|
if (!quadrants.includes(attributes.quadrant)) {
|
||||||
throw new Error("Error: ".concat(fileName, " has an illegal value for 'quadrant' - must be one of ").concat(quadrants));
|
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;
|
return attributes;
|
||||||
};
|
};
|
||||||
var createRevisionsFromFiles = function (fileNames) {
|
var createRevisionsFromFiles = function (fileNames) {
|
||||||
var publicUrl = process.env.PUBLIC_URL;
|
var publicUrl = process.env.PUBLIC_URL;
|
||||||
return Promise.all(fileNames.map(function (fileName) {
|
return Promise.all(fileNames.map(function (fileName) {
|
||||||
return new Promise(function (resolve, reject) {
|
return fs_extra_1.readFile(fileName, "utf8").then(function (data) {
|
||||||
(0, fs_extra_1.readFile)(fileName, "utf8", function (err, data) { return __awaiter(void 0, void 0, void 0, function () {
|
var fm = front_matter_1.default(data);
|
||||||
var fm, html;
|
var html = marked_1.marked(fm.body.replace(/\]\(\//g, "](" + publicUrl + "/"));
|
||||||
return __generator(this, function (_a) {
|
html = html.replace(/a href="http/g, 'a target="_blank" rel="noopener noreferrer" href="http');
|
||||||
if (err) {
|
var attributes = checkAttributes(fileName, fm.attributes);
|
||||||
reject(err);
|
if (attributes) {
|
||||||
}
|
return __assign(__assign(__assign({}, itemInfoFromFilename(fileName)), attributes), { fileName: fileName, body: html });
|
||||||
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*/];
|
|
||||||
});
|
|
||||||
}); });
|
|
||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -18,9 +18,10 @@ marked.setOptions({
|
|||||||
|
|
||||||
export const createRadar = async (): Promise<Radar> => {
|
export const createRadar = async (): Promise<Radar> => {
|
||||||
const fileNames = await getAllMarkdownFiles(radarPath());
|
const fileNames = await getAllMarkdownFiles(radarPath());
|
||||||
const revisions = await createRevisionsFromFiles(fileNames);
|
const revisions: (Revision|undefined)[] = await createRevisionsFromFiles(fileNames);
|
||||||
const allReleases = getAllReleases(revisions);
|
const filterdRevisions : Revision[] = revisions.filter(r => r !== undefined) as Revision[];
|
||||||
const items = createItems(revisions);
|
const allReleases = getAllReleases(filterdRevisions);
|
||||||
|
const items = createItems(filterdRevisions);
|
||||||
const flaggedItems = flagItem(items, allReleases);
|
const flaggedItems = flagItem(items, allReleases);
|
||||||
|
|
||||||
items.forEach(item => checkAttributes(item.name, item))
|
items.forEach(item => checkAttributes(item.name, item))
|
||||||
@@ -32,7 +33,7 @@ export const createRadar = async (): Promise<Radar> => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const checkAttributes = (fileName: string, attributes: FMAttributes) => {
|
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);
|
const config = JSON.parse(rawConf);
|
||||||
|
|
||||||
if (!config.rings.includes(attributes.ring)) {
|
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;
|
return attributes;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -56,28 +63,22 @@ const createRevisionsFromFiles = (fileNames: string[]) => {
|
|||||||
return Promise.all(
|
return Promise.all(
|
||||||
fileNames.map(
|
fileNames.map(
|
||||||
(fileName) =>
|
(fileName) =>
|
||||||
new Promise<Revision>((resolve, reject) => {
|
readFile(fileName, "utf8").then(data => {
|
||||||
readFile(fileName, "utf8", async (err, data) => {
|
const fm = frontMatter<FMAttributes>(data);
|
||||||
if (err) {
|
let html = marked(fm.body.replace(/\]\(\//g, `](${publicUrl}/`));
|
||||||
reject(err);
|
html = html.replace(
|
||||||
} else {
|
/a href="http/g,
|
||||||
const fm = frontMatter<FMAttributes>(data);
|
'a target="_blank" rel="noopener noreferrer" href="http'
|
||||||
// add target attribute to external links
|
);
|
||||||
// todo: check path
|
const attributes = checkAttributes(fileName, fm.attributes);
|
||||||
let html = marked(fm.body.replace(/\]\(\//g, `](${publicUrl}/`));
|
if (attributes) {
|
||||||
html = html.replace(
|
return {
|
||||||
/a href="http/g,
|
...itemInfoFromFilename(fileName),
|
||||||
'a target="_blank" rel="noopener noreferrer" href="http'
|
...attributes,
|
||||||
);
|
fileName,
|
||||||
|
body: html,
|
||||||
resolve({
|
} as Revision;
|
||||||
...itemInfoFromFilename(fileName),
|
}
|
||||||
...fm.attributes,
|
|
||||||
fileName,
|
|
||||||
body: html,
|
|
||||||
} as Revision);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ export type ItemAttributes = {
|
|||||||
quadrant: string;
|
quadrant: string;
|
||||||
title: string;
|
title: string;
|
||||||
featured?: boolean;
|
featured?: boolean;
|
||||||
|
radars?: string[];
|
||||||
};
|
};
|
||||||
|
|
||||||
export enum FlagType {
|
export enum FlagType {
|
||||||
|
|||||||
Reference in New Issue
Block a user