Skip to content

Commit

Permalink
Add support for media links in plugin manifest.json
Browse files Browse the repository at this point in the history
  • Loading branch information
Retr0ve committed Jul 18, 2022
1 parent 520d974 commit e4ce372
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
"homepage_url": "<%= pluginHomepageUrl %>",
"repository_url": "<%= pluginRepositoryUrl %>",
"keywords": [],
"categories": []
"categories": [],
"media": []
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ const userConfig = Object.assign({}, {
const manifestPath = `${srcDir}/manifest.json`;
const packageJsonPath = `${rootDir}/package.json`;
const allPossibleCategories = ['appearance', 'developer tools', 'productivity', 'themes', 'integrations', 'viewer', 'search', 'tags', 'editor', 'files', 'personal knowledge management'];
const allPossiblePlatform = ['desktop', 'mobile'];
const allPossibleMediaType = ['image/jpeg', 'image/png', 'image/gif', 'image/webp', 'video/mp4', 'video/webm', 'video/ogg'];
const manifest = readManifest(manifestPath);
const pluginArchiveFilePath = path.resolve(publishDir, `${manifest.id}.jpl`);
const pluginInfoFilePath = path.resolve(publishDir, `${manifest.id}.json`);
Expand Down Expand Up @@ -76,11 +78,22 @@ function validateCategories(categories) {
});
}

function validateMedia(media) {
if (!media) return null;
media.forEach(mediaItem => {
if (!mediaItem.url) throw new Error('You must specify a url for each media item');
if (mediaItem.platform && !allPossiblePlatform.includes(mediaItem.platform)) throw new Error(`${mediaItem.platform} is not a valid platform. Please make sure that the platform name is lowercase. Valid Platforms are: \n${allPossiblePlatform}\n`);
if (!mediaItem.type) throw new Error('You must specify the type of the media item');
if (mediaItem.type && !allPossibleMediaType.includes(mediaItem.type)) throw new Error(`${mediaItem.type} is not a valid media type. Valid media types are: \n${allPossibleMediaType}\n`);
});
}

function readManifest(manifestPath) {
const content = fs.readFileSync(manifestPath, 'utf8');
const output = JSON.parse(content);
if (!output.id) throw new Error(`Manifest plugin ID is not set in ${manifestPath}`);
validateCategories(output.categories);
validateMedia(output.media);
return output;
}

Expand Down
1 change: 1 addition & 0 deletions packages/lib/services/plugins/utils/manifestFromObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ export default function manifestFromObject(o: any): PluginManifest {
repository_url: getString('repository_url', false),
keywords: getStrings('keywords', false),
categories: getStrings('categories', false),
media: getStrings('media', false),
permissions: permissions,

_recommended: getBoolean('_recommended', false, false),
Expand Down
1 change: 1 addition & 0 deletions packages/lib/services/plugins/utils/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export interface PluginManifest {
repository_url?: string;
keywords?: string[];
categories?: string[];
media?: string[];
permissions?: PluginPermission[];

// Private keys
Expand Down
22 changes: 20 additions & 2 deletions readme/api/references/plugin_manifest.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ Name | Type | Required? | Description
`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.
`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.
`media` | string[] | No | Media urls related to the plguin. It is used for listing on Joplin Plugin website.

## Categories

Expand All @@ -31,6 +32,17 @@ Name | Type | Required? | Description
| themes | changing theme of the app. |
| viewer | enhancing the rendering of a note. |

## Media

You can store media such as images and videos in this field for listing on Joplin Plugin website.
| Field | Description |
| --- | --- |
| url | a remote url to your media |
| type | MIME type of your media, it can be `image/jpeg`, `image/png`, `image/gif`, `image/webp`, `video/mp4`, `video/webm`, and `video/ogg` |
| platform | a string that can define the distribution platform for which the specific media should apply to, it can be `destktop` or `mobile` |
| label | a string that serves as an accessible name for the media |


## Manifest example

```json
Expand All @@ -41,6 +53,12 @@ Name | Type | Required? | Description
"version": "1.0.0",
"author": "John Smith",
"app_min_version": "1.4",
"homepage_url": "https://joplinapp.org"
"homepage_url": "https://joplinapp.org",
"media": [{
"url": "https://raw.githubusercontent.com/laurent22/joplin/dev/Assets/ImageSources/RoundedCorners_64x64.png",
"type": "image/png",
"platform": "desktop",
"label": "Description"
}]
}
```

0 comments on commit e4ce372

Please sign in to comment.