1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-11-27 08:21:03 +02:00

Plugins: Add support for media links in plugin manifest.json (#6672)

This commit is contained in:
Retrove 2022-08-27 19:11:56 +08:00 committed by GitHub
parent 0356cbbfab
commit 58dc4feee7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 48 additions and 4 deletions

View File

@ -9,5 +9,6 @@
"homepage_url": "<%= pluginHomepageUrl %>", "homepage_url": "<%= pluginHomepageUrl %>",
"repository_url": "<%= pluginRepositoryUrl %>", "repository_url": "<%= pluginRepositoryUrl %>",
"keywords": [], "keywords": [],
"categories": [] "categories": [],
"screenshots": []
} }

View File

@ -30,6 +30,7 @@ const userConfig = Object.assign({}, {
const manifestPath = `${srcDir}/manifest.json`; const manifestPath = `${srcDir}/manifest.json`;
const packageJsonPath = `${rootDir}/package.json`; const packageJsonPath = `${rootDir}/package.json`;
const allPossibleCategories = ['appearance', 'developer tools', 'productivity', 'themes', 'integrations', 'viewer', 'search', 'tags', 'editor', 'files', 'personal knowledge management']; const allPossibleCategories = ['appearance', 'developer tools', 'productivity', 'themes', 'integrations', 'viewer', 'search', 'tags', 'editor', 'files', 'personal knowledge management'];
const allPossibleScreenshotsType = ['jpg', 'jpeg', 'png', 'gif', 'webp'];
const manifest = readManifest(manifestPath); const manifest = readManifest(manifestPath);
const pluginArchiveFilePath = path.resolve(publishDir, `${manifest.id}.jpl`); const pluginArchiveFilePath = path.resolve(publishDir, `${manifest.id}.jpl`);
const pluginInfoFilePath = path.resolve(publishDir, `${manifest.id}.json`); const pluginInfoFilePath = path.resolve(publishDir, `${manifest.id}.json`);
@ -76,11 +77,29 @@ function validateCategories(categories) {
}); });
} }
function validateScreenshots(screenshots) {
if (!screenshots) return null;
screenshots.forEach(screenshot => {
if (!screenshot.src) throw new Error('You must specify a src for each screenshot');
const screenshotType = screenshot.src.split('.').pop();
if (!allPossibleScreenshotsType.includes(screenshotType)) throw new Error(`${screenshotType} is not a valid screenshot type. Valid types are: \n${allPossibleScreenshotsType}\n`);
const screenshotPath = path.resolve(srcDir, screenshot.src);
// Max file size is 1MB
const fileMaxSize = 1024;
const fileSize = fs.statSync(screenshotPath).size / 1024;
if (fileSize > fileMaxSize) throw new Error(`Max screenshot file size is ${fileMaxSize}KB. ${screenshotPath} is ${fileSize}KB`);
});
}
function readManifest(manifestPath) { function readManifest(manifestPath) {
const content = fs.readFileSync(manifestPath, 'utf8'); const content = fs.readFileSync(manifestPath, 'utf8');
const output = JSON.parse(content); const output = JSON.parse(content);
if (!output.id) throw new Error(`Manifest plugin ID is not set in ${manifestPath}`); if (!output.id) throw new Error(`Manifest plugin ID is not set in ${manifestPath}`);
validateCategories(output.categories); validateCategories(output.categories);
validateScreenshots(output.screenshots);
return output; return output;
} }

View File

@ -1,4 +1,4 @@
import { PluginManifest, PluginPermission } from './types'; import { PluginManifest, PluginPermission, Screenshot } from './types';
import validatePluginId from './validatePluginId'; import validatePluginId from './validatePluginId';
export default function manifestFromObject(o: any): PluginManifest { export default function manifestFromObject(o: any): PluginManifest {
@ -31,6 +31,11 @@ export default function manifestFromObject(o: any): PluginManifest {
return o[name]; return o[name];
}; };
const getScreenshots = (defaultValue: Screenshot[] = []): Screenshot[] => {
if (!o.screenshots) return defaultValue;
return o.screenshots;
};
const permissions: PluginPermission[] = []; const permissions: PluginPermission[] = [];
const manifest: PluginManifest = { const manifest: PluginManifest = {
@ -46,6 +51,7 @@ export default function manifestFromObject(o: any): PluginManifest {
repository_url: getString('repository_url', false), repository_url: getString('repository_url', false),
keywords: getStrings('keywords', false), keywords: getStrings('keywords', false),
categories: getStrings('categories', false), categories: getStrings('categories', false),
screenshots: getScreenshots(),
permissions: permissions, permissions: permissions,
_recommended: getBoolean('_recommended', false, false), _recommended: getBoolean('_recommended', false, false),

View File

@ -2,6 +2,11 @@ export enum PluginPermission {
Model = 'model', Model = 'model',
} }
export interface Screenshot {
src: string;
label: string;
}
export interface PluginManifest { export interface PluginManifest {
manifest_version: number; manifest_version: number;
id: string; id: string;
@ -14,6 +19,7 @@ export interface PluginManifest {
repository_url?: string; repository_url?: string;
keywords?: string[]; keywords?: string[];
categories?: string[]; categories?: string[];
screenshots?: Screenshot[];
permissions?: PluginPermission[]; permissions?: PluginPermission[];
// Private keys // Private keys

View File

@ -13,7 +13,8 @@ Name | Type | Required? | Description
`keywords` | string[] | No | Keywords associated with the plugins. They are used in search in particular. `keywords` | string[] | No | Keywords associated with the plugins. They are used in search in particular.
`homepage_url` | string | No | Homepage URL of the plugin. It can also be, for example, a link to a GitHub repository. `homepage_url` | string | No | Homepage URL of the plugin. It can also be, for example, a link to a GitHub repository.
`repository_url` | string | No | Repository URL where the plugin source code is hosted. `repository_url` | string | No | Repository URL where the plugin source code is hosted.
`categories` | string[] | No | [Categories](#categories) that describes the functionality of the plugin. | `categories` | string[] | No | [Categories](#categories) that describes the functionality of the plugin.
`screenshots` | Screenshot[] | No | [Screenshots](#Screenshot) are used for listing on Joplin Plugin website.
## Categories ## Categories
@ -31,6 +32,13 @@ Name | Type | Required? | Description
| themes | changing theme of the app. | | themes | changing theme of the app. |
| viewer | enhancing the rendering of a note. | | viewer | enhancing the rendering of a note. |
## Screenshot
| Properties | Description |
| --- | --- |
| src | a relative path to src dir. |
| label | description of the image. |
## Manifest example ## Manifest example
```json ```json
@ -41,6 +49,10 @@ Name | Type | Required? | Description
"version": "1.0.0", "version": "1.0.0",
"author": "John Smith", "author": "John Smith",
"app_min_version": "1.4", "app_min_version": "1.4",
"homepage_url": "https://joplinapp.org" "homepage_url": "https://joplinapp.org",
"screenshots": [{
"src": "path/to/image.png",
"label": "image description"
}]
} }
``` ```