Skip to content

Commit ef813e4

Browse files
authored
Render advanced metafield for categories (#588)
1 parent b6088ff commit ef813e4

File tree

4 files changed

+8
-7
lines changed

4 files changed

+8
-7
lines changed

src/components/metadata/MetaSimple.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,16 +95,16 @@ export class MetaSimple extends Component {
9595
);
9696
}
9797

98-
renderTagsInput() {
98+
renderTagsInput(key) {
9999
const { fieldValue, nameAttr, updateFieldValue, siteMeta } = this.props;
100-
const siteTags = (siteMeta && siteMeta.tags) || [];
100+
const suggestions = (siteMeta && siteMeta[key]) || [];
101101

102102
return (
103103
<MetaTags
104104
fieldValue={fieldValue}
105105
nameAttr={nameAttr}
106106
updateFieldValue={updateFieldValue}
107-
suggestions={siteTags}
107+
suggestions={suggestions}
108108
/>
109109
);
110110
}
@@ -122,7 +122,8 @@ export class MetaSimple extends Component {
122122
node = this.renderStaticFilePicker();
123123
break;
124124
case 'tags':
125-
node = this.renderTagsInput();
125+
case 'categories':
126+
node = this.renderTagsInput(fieldKey);
126127
break;
127128
default:
128129
node = this.renderEditable();

src/components/metadata/MetaTags.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ export default class MetaTags extends Component {
109109
if (!(pageTags instanceof Array)) {
110110
return (
111111
<span className="meta-error">
112-
Invalid array of tags! Found: <strong>{pageTags}</strong>
112+
Expected an array of items. Found: <strong>{pageTags}</strong>
113113
<br />
114114
<span onClick={() => this.rectifyTag(pageTags)}>Click here</span>
115115
to correct.

src/components/metadata/tests/metatags.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ describe('Components::MetaTags', () => {
4242
...defaultProps,
4343
fieldValue: 'foo',
4444
});
45-
const error = 'Invalid array of tags! Found: fooClick hereto correct.';
45+
const error = 'Expected an array of items. Found: fooClick hereto correct.';
4646
const error_element = component.find('.meta-error');
4747
const rectifier = error_element.find('span').last();
4848

src/utils/metadata.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ export const injectDefaultFields = (config, path, type, front_matter = {}) => {
159159
*/
160160
export const computeFieldType = (value, key = null) => {
161161
let type = 'simple';
162-
const specialKeys = ['tags'];
162+
const specialKeys = ['tags', 'categories'];
163163
if (specialKeys.includes(key) && _.isArray(value)) return type;
164164

165165
if (_.isObject(value)) type = 'object';

0 commit comments

Comments
 (0)