Filters Redesign (#658)
* Add XCheckboxFilter * Fix madara typo * Change the branch name in config * Add typing for madara popoularnovels filters * Add preview and refactor PluginWrapper * Add preview HTML sanitize and other improv. * Web improvements + sanitizeHTML * Add dark mode * Add git run less to compile less * Add less.js to remove the need for compiling less
This commit is contained in:
@@ -1,31 +1,50 @@
|
||||
import { FilterInputs } from "../../../libs/filterInputs";
|
||||
import { FilterTypes, Filters } from "../../../libs/filterInputs";
|
||||
import { ScrpitGeneratorFunction } from "../generate";
|
||||
import list from "./sources.json";
|
||||
import { MadaraMetadata } from "./template";
|
||||
import { readFileSync } from "fs";
|
||||
import path from "path";
|
||||
|
||||
|
||||
export const generateAll: ScrpitGeneratorFunction = function () {
|
||||
return list.map((metadata: MadaraMetadata) => {
|
||||
return generator(metadata);
|
||||
});
|
||||
export const generateAll: ScrpitGeneratorFunction = function (name) {
|
||||
return (
|
||||
list
|
||||
/* This map is changing `type` from string to FilterTypes */
|
||||
.map<MadaraMetadata>((p) => {
|
||||
let d = false;
|
||||
const filters: Filters = {};
|
||||
for (const k in p.filters) {
|
||||
const f = p.filters[k as "sort" | "genres"];
|
||||
if (f) {
|
||||
filters[k] = {
|
||||
...f,
|
||||
type: FilterTypes.Picker,
|
||||
};
|
||||
}
|
||||
}
|
||||
return { ...p, filters: d ? undefined : filters };
|
||||
})
|
||||
.map((metadata: MadaraMetadata) => {
|
||||
console.log(`[${name}]: Generating`, metadata.id);
|
||||
return generator(metadata);
|
||||
})
|
||||
);
|
||||
};
|
||||
|
||||
const generator = function generator(metadata: MadaraMetadata) {
|
||||
const lang = metadata.options?.lang || "English";
|
||||
|
||||
const madaraTemplate = readFileSync(path.join(__dirname, "template.ts"), {encoding: "utf-8"});
|
||||
metadata.filters = metadata.filters?.map((filter: any) => ({
|
||||
...filter,
|
||||
inputType: FilterInputs[filter.inputType]
|
||||
}));
|
||||
const madaraTemplate = readFileSync(path.join(__dirname, "template.ts"), {
|
||||
encoding: "utf-8",
|
||||
});
|
||||
|
||||
const pluginScript = `
|
||||
${madaraTemplate}
|
||||
const plugin = new MadaraPlugin(${JSON.stringify(metadata)});
|
||||
const plugin = new MadaraPlugin(${JSON.stringify(metadata).replace(
|
||||
/"type":"Picker"/g,
|
||||
`"type":FilterTypes.Picker`
|
||||
)});
|
||||
export default plugin;
|
||||
`
|
||||
`;
|
||||
return {
|
||||
lang,
|
||||
filename: metadata.sourceName,
|
||||
|
||||
Reference in New Issue
Block a user