Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parse plans in convertConfig #652

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions convert/convertConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,26 @@ export type ConfigData = {
file: string;
}[];
}[];

plans?: {
features: {
[key: string]: string;
};
plans: {
id: string;
days: number;
title: {
[lang: string]: string;
};
filename: string;
image?: {
width: number;
height: number;
file: string;
};
}[];
};

security?: {
// TODO
features?: {
Expand Down Expand Up @@ -1035,6 +1055,59 @@ function convertConfig(dataDir: string, verbose: number) {
}
}

//plans
const plansTags = document.getElementsByTagName('plans');
if (plansTags?.length > 0) {
const plansTag = plansTags[0];
const featuresTag = plansTag.getElementsByTagName('features')[0];
const features: { [key: string]: string } = {};
if (featuresTag) {
for (const feature of featuresTag.getElementsByTagName('e')) {
const name = feature.attributes.getNamedItem('name')!.value;
const value = feature.attributes.getNamedItem('value')!.value;
if (verbose >= 2)
console.log(`.. Converting feature: name=${name}, value=${value}`);
features[name] = value;
}
}

const planTags = plansTag.getElementsByTagName('plan');
const plans = [];
if (planTags?.length > 0) {
for (const tag of planTags) {
const titleTags = tag.getElementsByTagName('title')[0].getElementsByTagName('t');
const title: { [lang: string]: string } = {};
for (const titleTag of titleTags) {
title[titleTag.attributes.getNamedItem('lang')!.value] = titleTag.innerHTML;
}
//image
const imageTag = tag.getElementsByTagName('image')[0];

let image = undefined;
if (imageTag.innerHTML) {
image = {
width: Number(imageTag.attributes.getNamedItem('width')!.value),
height: Number(imageTag.attributes.getNamedItem('height')!.value),
file: imageTag.innerHTML
};
}

const plan = {
id: tag.attributes.getNamedItem('id')!.value,
days: Number(tag.attributes.getNamedItem('days')!.value),
title,
filename: tag.getElementsByTagName('filename')[0].innerHTML,
image
};
plans.push(plan);
}
data.plans = {
features,
plans
};
}
}

/*
security?: {
features?: {
Expand Down
Loading