Slide 1

Slide 1 text

Patience and the right tools @stefanjudis Ways to approach
 content modelling

Slide 2

Slide 2 text

Stefan Judis Frontend Developer, Occasional Teacher, Meetup Organizer ❤ Open Source, Performance and Accessibility ❤ @stefanjudis

Slide 3

Slide 3 text

Where we come from

Slide 4

Slide 4 text

Karen McGrane I don’t necessarily know where this content is going to live. I don’t know how it’s going to be used in the future. But, I do know that I have to create lots of flexible content that has metadata attached to it because I know it’s going to be reused in different places. “

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

It's like Lego

Slide 8

Slide 8 text

NOBODY(!) GETS IT RIGHT THE FIRST TIME...

Slide 9

Slide 9 text

share Share & reuse

Slide 10

Slide 10 text

github.com/joshhebb/angularjs-contentful-starter

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

www.npmjs.com/package/contentful-import www.npmjs.com/package/contentful-export

Slide 13

Slide 13 text

It's just code Setting up a space is quickly done

Slide 14

Slide 14 text

When you know how...

Slide 15

Slide 15 text

I believe in tooling and defaults!

Slide 16

Slide 16 text

Eat your own dog food

Slide 17

Slide 17 text

No content

Slide 18

Slide 18 text

USEFUL FOR ANYONE?

Slide 19

Slide 19 text

Share content models?

Slide 20

Slide 20 text

No content

Slide 21

Slide 21 text

www.contentfulcommunity.com MAYBE HERE?

Slide 22

Slide 22 text

Analyse

Slide 23

Slide 23 text

No content

Slide 24

Slide 24 text

www.npmjs.com/package/contentful-graph

Slide 25

Slide 25 text

No content

Slide 26

Slide 26 text

YOUR CONTENT MODEL VISUALISED.

Slide 27

Slide 27 text

No content

Slide 28

Slide 28 text

No content

Slide 29

Slide 29 text

CLI is great, but there is more

Slide 30

Slide 30 text

contentful-graph.yaraslav.com/

Slide 31

Slide 31 text

Evolve

Slide 32

Slide 32 text

Clean up time

Slide 33

Slide 33 text

www.npmjs.com/package/contentful-migration-cli

Slide 34

Slide 34 text

MIGRATION CLI CONTENT TYPE OPERATIONS Create a content type 01 02 03 04 05 Delete a content type Edit a content type Create/edit/delete fields Change a field ID

Slide 35

Slide 35 text

FIELDS TO DELETE

Slide 36

Slide 36 text

Drop fields module.exports = function (migration) { const event = migration.editContentType('event') const project = migration.editContentType('project') }

Slide 37

Slide 37 text

module.exports = function (migration) { const event = migration.editContentType('event') event.deleteField('hotel') event.deleteField('venue') const project = migration.editContentType('project') project.deleteField('screenshot') } Drop fields

Slide 38

Slide 38 text

No content

Slide 39

Slide 39 text

FIELDS TO RENAME VS

Slide 40

Slide 40 text

module.exports = function (migration) { const tilPost = migration.editContentType('tilPost') } Change field ID

Slide 41

Slide 41 text

module.exports = function (migration) { const tilPost = migration.editContentType('tilPost') tilPost.changeFieldId('categories', 'tags') tilPost.editField('tags', { name: 'Tags' }) tilPost.moveField('tags').afterField('date') } Change field ID

Slide 42

Slide 42 text

No content

Slide 43

Slide 43 text

FRONTTRENDS 2017 COUNTRY : PL CITY : WARSAW ... FRONTTRENDS 2018 COUNTRY : PL CITY : WARSAW ... DERIVE ENTRIES AND LINK

Slide 44

Slide 44 text

FT COUNTRY: PL CITY : WARSAW FRONTTRENDS 2017 COUNTRY : PL CITY : WARSAW ... FRONTTRENDS 2018 COUNTRY : PL CITY : WARSAW ... DERIVE ENTRIES AND LINK

Slide 45

Slide 45 text

FRONTTRENDS 2017 CONFERENCE : FT ... FRONTTRENDS 2018 CONFERENCE : FT ... FT COUNTRY: PL CITY : WARSAW DERIVE ENTRIES AND LINK

Slide 46

Slide 46 text

A looong manual nightshift

Slide 47

Slide 47 text

No way!

Slide 48

Slide 48 text

repetetive error-prone not scalable MANUAL CONTENT MODEL CHANGES ARE NOT THE SOLUTION

Slide 49

Slide 49 text

Transform an entry in place 01 02 Derive an entry from another MIGRATION CLI CONTENT TRANSFORMATIONS

Slide 50

Slide 50 text

module.exports = function (migration) { const conference = migration.createContentType('conference') .name('Conference/Meetup') .displayField('name') conference.createField('name') .type('Symbol') .required(true) .name('Conference/Meetup name') conference.createField('country') .type('Symbol') .required(true) .name('Country Code') conference.createField('city') .type('Symbol') .required(true) .name('City') Derive entries and link

Slide 51

Slide 51 text

.name('Country Code') conference.createField('city') .type('Symbol') .required(true) .name('City') const event = migration.editContentType('event') event.createField('conference') .name('Conference') .type('Link') .linkType('Entry') .validations([ { "linkContentType": ['conference'] } ]) Derive entries and link

Slide 52

Slide 52 text

]) migration.deriveLinkedEntries({ contentType: 'event', from: ['name', 'country', 'city'], toReferenceField: 'conference', derivedContentType: 'conference', derivedFields: ['name', 'country', 'city'], identityKey: async (from) => { return getId(from.name['en-US']) }, deriveEntryForLocale: async (inputFields, locale) => { return { name: inputFields.name[locale].replace(/\s(\d{2,4}|#\d+)/g, ''), country: inputFields.country[locale] || 'N/A', city: inputFields.city[locale] || 'N/A' } } }) Derive entries and link

Slide 53

Slide 53 text

]) migration.deriveLinkedEntries({ contentType: 'event', from: ['name', 'country', 'city'], toReferenceField: 'conference', derivedContentType: 'conference', derivedFields: ['name', 'country', 'city'], identityKey: async (from) => { return getId(from.name['en-US']) }, deriveEntryForLocale: async (inputFields, locale) => { return { name: inputFields.name[locale].replace(/\s(\d{2,4}|#\d+)/g, ''), country: inputFields.country[locale] || 'N/A', city: inputFields.city[locale] || 'N/A' } } }) Derive entries and link

Slide 54

Slide 54 text

]) migration.deriveLinkedEntries({ contentType: 'event', from: ['name', 'country', 'city'], toReferenceField: 'conference', derivedContentType: 'conference', derivedFields: ['name', 'country', 'city'], identityKey: async (from) => { return getId(from.name['en-US']) }, deriveEntryForLocale: async (inputFields, locale) => { return { name: inputFields.name[locale].replace(/\s(\d{2,4}|#\d+)/g, ''), country: inputFields.country[locale] || 'N/A', city: inputFields.city[locale] || 'N/A' } } }) Derive entries and link

Slide 55

Slide 55 text

]) migration.deriveLinkedEntries({ contentType: 'event', from: ['name', 'country', 'city'], toReferenceField: 'conference', derivedContentType: 'conference', derivedFields: ['name', 'country', 'city'], identityKey: async (from) => { return getId(from.name['en-US']) }, deriveEntryForLocale: async (inputFields, locale) => { return { name: inputFields.name[locale].replace(/\s(\d{2,4}|#\d+)/g, ''), country: inputFields.country[locale] || 'N/A', city: inputFields.city[locale] || 'N/A' } } }) Derive entries and link

Slide 56

Slide 56 text

} } }) event.moveField('conference').afterField('name') event.deleteField('country') event.deleteField('city') } Derive entries and link

Slide 57

Slide 57 text

No content

Slide 58

Slide 58 text

module.exports = function (migration) { const conference = migration.createContentType('conference') .name('Conference/Meetup') .displayField('name') conference.createField('name').type('Symbol').required(true).name('Conference/Meetup name') conference.createField('country').type('Symbol').required(true).name('Country Code') conference.createField('city').type('Symbol').required(true).name('City') const event = migration.editContentType('event') event.createField('conference') .name('Conference') .type('Link') .linkType('Entry') .validations([ { "linkContentType": ['conference'] } ]) migration.deriveLinkedEntries({ contentType: 'event', from: ['name', 'country', 'city'], toReferenceField: 'conference', derivedContentType: 'conference', derivedFields: ['name', 'country', 'city'], identityKey: async (from) => { return from.name['en-US'] // remove year .replace(/\s(\d{2,4}|#\d+)/g, '') // clear spaces .replace(/\s/g, '-') // clear "weird characters" .replace(/(,|\/|\\|:|\.|\(|\))/g, '') .toLowerCase() }, deriveEntryForLocale: async (inputFields, locale) => { return { name: inputFields.name[locale].replace(/\s(\d{2,4}|#\d+)/g, ''), country: inputFields.country[locale] || 'N/A', city: inputFields.city[locale] || 'N/A' } } }) event.moveField('conference').afterField('name') event.deleteField('country') event.deleteField('city') } LOC 48 REQUESTS 382 ENTRIES CREATED 88 ENTRIES UPDATED 96

Slide 59

Slide 59 text

MIGRATION CLI ADVANTAGES Repeatable 01 02 03 04 Can be kept in VC Includes sanity checks Perfect for CI

Slide 60

Slide 60 text

NOBODY(!) GETS IT RIGHT THE FIRST TIME...

Slide 61

Slide 61 text

61 WAYS TO SURVIVE SHARE & REUSE ANALYSE EVOLVE

Slide 62

Slide 62 text

with the right tools...

Slide 63

Slide 63 text

Thanks. @stefanjudis Slides ctfl.io/content-modelling-is-tricky Article ctfl.io/content-modelling-is-tricky-article