change overview internal reference to readme, some cleanup

pull/69/head
dperolio 3 years ago
parent 274b3e35ba
commit ed735105dc
No known key found for this signature in database
GPG Key ID: 3E9BBAA710D3DDCE

@ -34,6 +34,7 @@ export default class Plugin extends Updatable {
this._watcherEnabled = null;
this._watcher = {};
this._labels = [ 'Plugin', this.manifest?.name || this.constructor?.name ];
this._registerSections();
}
/**
@ -314,7 +315,6 @@ export default class Plugin extends Updatable {
*
*/
await this._registerSettings();
await this._registerSections();
} else {
this.warn(`${toTitleCase(this.type)} has no "start" method!`);
}
@ -377,41 +377,65 @@ export default class Plugin extends Updatable {
*/
async _registerSections () {
try {
[ 'readme', 'changelog' ].forEach(section => {
/**
*
*/
let sectionPath;
if (this.sections && !this.sections[section]) {
if (this.manifest?.sections && this.manifest.sections[section]) {
if (existsSync(join(this.path, this.manifest.sections[section]))) {
sectionPath = join(this.path, this.manifest.sections[section]);
}
/**
* @todo Possibly allow any case for these file names.
*/
} else if (existsSync(join(this.path, `${section.toUpperCase()}.md`))) {
sectionPath = join(this.path, `${section.toUpperCase()}.md`);
} else if (existsSync(join(this.path, section.toUpperCase()))) {
sectionPath = join(this.path, section.toUpperCase());
}
if (sectionPath) {
this.sections[section] = readFileSync(sectionPath, 'utf8');
}
}
});
return;
/**
*
*/
let changelogPath;
if (this.type !== 'builtin') {
if (!this.sections.changelog) {
if (this.manifest?.sections?.changelog) {
if (existsSync(join(this.path, this.manifest.sections.changelog))) {
changelogPath = join(this.path, this.manifest.sections.changelog);
}
} else if (existsSync(join(this.path, 'CHANGELOG.md'))) {
changelogPath = join(this.path, 'CHANGELOG.md');
} else if (existsSync(join(this.path, 'CHANGELOG'))) {
changelogPath = join(this.path, 'CHANGELOG');
if (!this.sections.changelog) {
if (this.manifest?.sections?.changelog) {
if (existsSync(join(this.path, this.manifest.sections.changelog))) {
changelogPath = join(this.path, this.manifest.sections.changelog);
}
} else if (existsSync(join(this.path, 'CHANGELOG.md'))) {
changelogPath = join(this.path, 'CHANGELOG.md');
} else if (existsSync(join(this.path, 'CHANGELOG'))) {
changelogPath = join(this.path, 'CHANGELOG');
}
if (changelogPath) {
this.sections.changelog = readFileSync(changelogPath, 'utf8');
}
}
if (changelogPath) {
this.sections.changelog = readFileSync(changelogPath, 'utf8');
}
let readmePath;
if (!this.sections.overview) {
if (this.manifest?.sections?.overview) {
if (existsSync(join(this.path, this.manifest.sections.overview))) {
readmePath = join(this.path, this.manifest.sections.overview);
}
} else if (existsSync(join(this.path, 'README.md'))) {
readmePath = join(this.path, 'README.md');
} else if (existsSync(join(this.path, 'README'))) {
readmePath = join(this.path, 'README');
let readmePath;
if (!this.sections.overview) {
if (this.manifest?.sections?.overview) {
if (existsSync(join(this.path, this.manifest.sections.overview))) {
readmePath = join(this.path, this.manifest.sections.overview);
}
} else if (existsSync(join(this.path, 'README.md'))) {
readmePath = join(this.path, 'README.md');
} else if (existsSync(join(this.path, 'README'))) {
readmePath = join(this.path, 'README');
}
if (readmePath) {
this.sections.overview = readFileSync(readmePath, 'utf8');
}
}
if (readmePath) {
this.sections.overview = readFileSync(readmePath, 'utf8');
}
} catch (err) {
return this.error(err);

@ -149,12 +149,12 @@ export default class AddonManager extends Events {
* @param {string} addonId Addon ID
* @returns
*/
hasOverview (addonId) {
hasReadme (addonId) {
try {
const addon = this.get(addonId);
return Boolean(addon?.sections?.overview);
return Boolean(addon?.sections?.readme);
} catch (err) {
return this._error(`An error occurred while checking for overview for "${addonId}"!`, err);
return this._error(`An error occurred while checking for readme for "${addonId}"!`, err);
}
}

@ -44,7 +44,7 @@ export default memo(({ addonId, type, section }) => {
let addon = vizality.manager[toPlural(type)].get(addonId);
const hasSettings = vizality.manager[toPlural(type)].hasSettings(addonId);
const hasChangelog = vizality.manager[toPlural(type)].hasChangelog(addonId);
const hasOverview = vizality.manager[toPlural(type)].hasOverview(addonId);
const hasReadme = vizality.manager[toPlural(type)].hasReadme(addonId);
const isEnabled = vizality.manager[toPlural(type)].isEnabled(addonId);
const isInstalled = vizality.manager[toPlural(type)].isInstalled(addonId);
const hasScreenshots = vizality.manager[toPlural(type)].hasScreenshots(addonId);
@ -134,9 +134,9 @@ export default memo(({ addonId, type, section }) => {
</__TabBar>
</StickyElement>
<div className='vz-addon-listing-content'>
{hasOverview && section === 'overview' && (
{hasReadme && section === 'overview' && (
<Section header='Overview' icon='InfoFilled'>
<Markdown source={addon.sections.overview} addonId={addonId} type={type} />
<Markdown source={addon.sections.readme} addonId={addonId} type={type} />
</Section>
)}
{hasScreenshots && section === 'screenshots' && (

Loading…
Cancel
Save