Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jasonsturges/apple-news-compiler
Apple News format compiler for optimized JSON article
https://github.com/jasonsturges/apple-news-compiler
apple-news apple-news-format json
Last synced: about 1 month ago
JSON representation
Apple News format compiler for optimized JSON article
- Host: GitHub
- URL: https://github.com/jasonsturges/apple-news-compiler
- Owner: jasonsturges
- License: mit
- Created: 2019-03-24T17:47:25.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2019-04-06T21:26:24.000Z (over 5 years ago)
- Last Synced: 2024-10-13T17:21:41.353Z (2 months ago)
- Topics: apple-news, apple-news-format, json
- Language: JavaScript
- Size: 29.3 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Apple News Compiler
Apple News format compiler for optimized JSON article## Inline
Replace all named component layouts, styles, and text styles by inlining object definitions within the article's components array.
Example:
```js
const fs = require("fs");
const anf = require("apple-news-compiler");const run = async () => {
const article = JSON.parse(fs.readFileSync("article.json"), 'utf8');anf.article.inline(article);
console.log(JSON.stringify(article, null, 2));
};run();
```Original article.json:
```json
{
"role": "title",
"text": "Title on Scrim",
"layout": "titleLayout",
"textStyle": "titleStyle"
}
```Inline will replace named references of `titleLayout` and `titleStyle` with object definitions:
```json
{
"role": "title",
"text": "Title on Scrim",
"layout": {
"columnStart": 0,
"columnSpan": 7,
"margin": {
"top": 50,
"bottom": 5
}
},
"textStyle": {
"textAlignment": "center",
"fontName": "HelveticaNeue-Bold",
"fontSize": 42,
"lineHeight": 50,
"textColor": "#EFEFEF"
}
}
```## Remove Unused References
Purge any unused references to layouts, styles, or text styles not referenced by name within the components array.
This optimization removes lengthy templated style definitions that may be stubbed into an article boilerplate, leaving only definitions that are actually used. Note this does not purge empty object definitions - use `removeEmptyDefinitions()`.
Example:
```js
const fs = require("fs");
const anf = require("apple-news-compiler");const run = async () => {
const article = JSON.parse(fs.readFileSync("article.json"), 'utf8');anf.article.removeUnusedReferences(article);
console.log(JSON.stringify(article, null, 2));
};run();
```## Remove Empty Definitions
Purge any empty definitions within layouts, styles, or text styles as well as their named reference within the components array.
This optimization removes lengthy templated style definitions that may be stubbed into an article boilerplate.
Example:
```js
const fs = require("fs");
const anf = require("apple-news-compiler");const run = async () => {
const article = JSON.parse(fs.readFileSync("article.json"), 'utf8');anf.article.removeEmptyDefinitions(article);
console.log(JSON.stringify(article, null, 2));
};run();
```Original article.json
```json
"components": [
{
"role": "title",
"text": "Title on Scrim",
"layout": "titleLayout",
"textStyle": "titleStyle"
}
],
"componentTextStyles": {
"titleStyle": {
}
}
```In the example above, `titleStyle` is empty - no style was defined in the object. Therefore, the resulting optimization would remove the component's `"textStyle": "titleStyle"` as well as the empty `titleStyle` from `componentTextStyles`:
```json
"components": [
{
"role": "title",
"text": "Title on Scrim",
"layout": "titleLayout"
}
],
"componentTextStyles": {}
```## Remove Comments
Purge any comments from components, layouts, styles, or text styles that use either the following conventions:
```json
{
"//": "Comment example"
}
```Or:
```json
{
"comment": "Comment example"
}
```