Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonsturges committed Mar 26, 2019
1 parent 5e6e1f5 commit ebc0a72
Showing 1 changed file with 58 additions and 2 deletions.
60 changes: 58 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const run = async () => {
run();
```

Original article.json
Original article.json:

```json
{
Expand Down Expand Up @@ -62,7 +62,7 @@ Inline will replace named references of `titleLayout` and `titleStyle` with obje

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.
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:

Expand All @@ -82,6 +82,62 @@ 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 () => {
var 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 optimizaiton would remove `titleStyle` from the component's `textStyle` as well as the `titleStyle` from the `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:
Expand Down

0 comments on commit ebc0a72

Please sign in to comment.