Modify schema.js and add linkedin to Structured Data

Hi together,

I am facing the following challenge: For all the authors on my website https://bitcoin-2go.de I would like to extend the structured data with linkedin.

Therefore the JSON-LD for authors should look like:

{
    "@context": "https://schema.org",
    "@type": "Person",
    "sameAs": [
        "link-to-website",
        "link-to-twitter",
        "link-to-facebook",
        "link-to-linkedin"
    ],
    "name": "author name",
    "url": "https://bitcoin-2go.de/author/name-surname",
    "image": {
        "@type": "ImageObject",
        "url": "https://bitcoin-2go.de/content/images/2021/07/twitch_banner-1.png",
        "width": 2240,
        "height": 1260
    },
    "mainEntityOfPage": {
        "@type": "WebPage",
        "@id": "https://bitcoin-2go.de/"
    },
    "description": "Author description."
}

However, achieving this goal is not as easy as I thought.

So far, I have done the following steps:

Step 1:

I have opened /core/frontend/meta/schema.js and modified the trimSameAs(data, context) function to the following:

function trimSameAs(data, context) {
    const sameAs = [];

    if (context === 'post' || context === 'page') {
        if (data[context].primary_author.website) {
            sameAs.push(escapeExpression(data[context].primary_author.website));
        }
        if (data[context].primary_author.facebook) {
            sameAs.push(socialUrls.facebook(data[context].primary_author.facebook));
        }
        if (data[context].primary_author.twitter) {
            sameAs.push(socialUrls.twitter(data[context].primary_author.twitter));
        }
        if (data[context].primary_author.linkedin) {
            sameAs.push(escapeExpression(data[context].primary_author.linkedin));
        }
    } else if (context === 'author') {
        if (data.author.website) {
            sameAs.push(escapeExpression(data.author.website));
        }
        if (data.author.facebook) {
            sameAs.push(socialUrls.facebook(data.author.facebook));
        }
        if (data.author.twitter) {
            sameAs.push(socialUrls.twitter(data.author.twitter));
        }
        if (data.author.linkedin) {
            sameAs.push(escapeExpression(data.author.linkedin));
        }
    }

    return sameAs;
}

Step 2:

I have downloaded the .json-file of my database. For each author I tried to add the following property:

"twitter": "@example",
"linkedin": "url-to-linkedin"

After doing the modifications, I uploaded the .json-file and realized afterwards (when downloading it again) that the key-value property was deleted.

Step 3:

I concluded that the property was deleted, since there was no approriate definition made in /core/server/data/schema/schema.js. Afterwards, I opened the file and and edited the users-property to get the following result:

users:{
website: {type: 'string', maxlength: 2000, nullable: true, validations: {isEmptyOrURL: true}},
        location: {type: 'text', maxlength: 65535, nullable: true, validations: {isLength: {max: 150}}},
        facebook: {type: 'string', maxlength: 2000, nullable: true},
        twitter: {type: 'string', maxlength: 2000, nullable: true},
        linkedin: {type: 'string', maxlength: 2000, nullable: true},
       ....
}

After restarting ghost, I ended up with a 503-error.

Would be extremely thankful if you could give me hints and ideas of where I should look next :slight_smile:

The schema file is the golden file that’s used to initialize your database, or perform certain validations against data before it’s added to the database. If you’re trying to change the database, you have to write a migration to do that, make sure the migration is correct, and make sure that it can be undone.

On top of that, you have to add support for linkedin in the exporter, API, admin interface, etc. and keep those changes in sync with Ghost.

If you’re able to I’d suggest using a different field as the linkedin reference and override your schema generator to support it