Skip to content

Metadata pointers

Metadata pointers tell the publisher where to get metadata values from other files in your project, usually .json or built .html files.

Pointer structure

{
path: 'locales/en/content.json?story.authors',
format: (value: string[]) => {
return value.join(', ');
},
validate: (value: string) => value.length > 3,
promptAsInitial: false,
}
// ... or shorthanded with just path
'locales/en/content.json?story.authors'

path

Pointer paths are a compound string of the relative path to a file and the JSON path to a data value within it.

For example, a path like:

{
path: 'locales/en/content.json?story.title',
}

… would point at the following value:

locales/en/content.json
{
"story": {
"title": "My page title"
}
}

Can also be used to get values from built HTML files like:

{
path: 'dist/index.html?title',
}
dist/index.html
<html>
<head>
<title>My page title</title>
</head>
<body></body>
</html>

See more examples at @reuters-graphics/graphics-bin.

Shorthand syntax

A metadata pointer can also be defined as just the path string.

'locales/en/content.json?story.title';

format

An optional format function to run when the value is found in a file.

For example:

{
path: 'locales/en/content.json?story.authors',
format: (value: string[]) => {
return value.join(', ');
},
}

… could be used to format an array of strings like the following into a single string.

locales/en/content.json
{
"story": {
"authors": ["Jane Doe", "John Doe"]
}
}

validate

An optional function to validate the value found in the metadata file.

For example:

{
path: '~/.reuters-graphics/profile.json?email',
validate: (value: string) => {
// Returns true if value is a TR email
return /.+@thomsonreuters\.com$/.test(value);
},
}

promptAsInitial

If the pointer finds a value, use it as the initial value in a prompt to the user. If set to false or not defined, skips the prompt if the pointer finds a value and uses it directly.

{
path: 'locales/en/content.json?story.title',
promptAsInitial: true,
}

Pointers

publisher.config.ts
import { defineConfig } from '@reuters-graphics/graphics-kit-publisher';
export default defineConfig({
metadataPointers: {
pack: {
rootSlug: 'locales/en/content.json?story.rootSlug',
wildSlug: 'locales/en/content.json?story.wildSlug',
desk: {
path: '~/.reuters-graphics/profile.json?desk',
promptAsInitial: true,
},
language: 'en',
title: 'dist/index.html?title',
byline: 'locales/en/content.json?story.authors',
contactEmail: '~/.reuters-graphics/profile.json?email',
},
edition: {
title: 'index.html?title',
description: 'index.html?meta.og:description',
},
},
});

pack.rootSlug

  • Type:
    string | MetadataPointer<string, string>;
  • Default:
    'locales/en/content.json?story.rootSlug';

pack.wildSlug

  • Type:
    string | MetadataPointer<string, string>;
  • Default:
    'locales/en/content.json?story.wildSlug';

pack.desk

  • Type:
    string | MetadataPointer<string, string>;
  • Default:
    { path: '~/.reuters-graphics/profile.json?desk', promptAsInitial: true }

pack.language

  • Type:
    RNGS.Language | MetadataPointer<string, string>;
  • Default:
    'en';

pack.title

  • Type:
    string | MetadataPointer<string, string>;
  • Default:
    'dist/index.html?title';

pack.byline

  • Type:
    string | MetadataPointer<string, string>;
  • Default:
    'locales/en/content.json?story.authors';

pack.contactEmail

  • Type:
    string | MetadataPointer<string, string>;
  • Default:
    '~/.reuters-graphics/profile.json?email';

edition.title

  • Type:
    string | MetadataPointer<string, string>;
  • Default:
    'index.html?title';

edition.description

  • Type:
    string | MetadataPointer<string, string>;
  • Default:
    'index.html?meta.og:description';