Skip to content

Commit

Permalink
Restrict extractor options to a specific template
Browse files Browse the repository at this point in the history
  • Loading branch information
sylvainjule committed Mar 18, 2019
1 parent 6f3af17 commit e1113b6
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 4 deletions.
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ palette:

#### 4.1. Select manually which image to extract colors from

You can extract a color palette from an image file by activating the `extractor` option. It will override the manual options, if specified. Default is `false`.
You can extract a color palette from a page's image file by activating the `extractor` option. It will override the manual options, if specified. Default is `false`.

```yaml
palette:
Expand All @@ -191,6 +191,15 @@ palette:
# no need for options anymore
```

You can restrict the choices to a specific file template with the `template` option:

```yaml
palette:
type: color-palette
extractor: true
template: cover
```

#### 4.2. Automatically extract colors when an image matches a template

Alternatively, you can make use of the `autotemplate` option (do not add the above `extractor` option in this case).
Expand Down
2 changes: 1 addition & 1 deletion index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion lib/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
'method' => 'GET',
'action' => function () {
$uri = get('uri');
$template = get('template');
$page = kirby()->page($uri);
$files = $page->images();
$files = $template !== 'undefined' ? $page->images()->template($template) : $page->images();
$data = [];

$thumb = array(
Expand Down
3 changes: 3 additions & 0 deletions lib/fields.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
$yaml = Yaml::decode($value);
return count($yaml) ? $yaml : $value;
},
'template' > function($template = null) {
return $template;
},
'autotemplate' > function($autotemplate = null) {
return $autotemplate;
}
Expand Down
3 changes: 2 additions & 1 deletion src/components/field/ColorPalette.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export default {
uri: String,
endpoints: Object,
autotemplate: String,
template: String,
// general options
label: String,
Expand Down Expand Up @@ -167,7 +168,7 @@ export default {
return true;
},
openSelector() {
this.$api.get('color-palette/get-files', {uri: this.uri})
this.$api.get('color-palette/get-files', {uri: this.uri, template: this.template})
.then(files => {
this.$refs.selector.open(files, {
max: false,
Expand Down

0 comments on commit e1113b6

Please sign in to comment.