Grav: Common MetaData for multilanguage pages

Created on 31 Mar 2016  路  7Comments  路  Source: getgrav/grav

working with multiple languages I find myself copying common meta-data / header settings between the language variants.

Would be great to have a solution, where there is first loaded a common meta data file, which then might be overwritten by the actual language files, e.g.

/default.meta.yaml    <- common meta data, header etc
/default.en.md <- partially overrides for EN
/default.de.md <- partially overrides for DE
investigating question

Most helpful comment

Ok, I created a PR for a solution to this. I made it a generic frontmatter.yaml file that was used so you could set any header (including metadata).

https://github.com/getgrav/grav/pull/775

IMPORTANT Please read my comments about the caveats of this: https://github.com/getgrav/grav/pull/775#issue-146441825

metadata:
    generator: 'Super Grav'
    description: from frontmatter.yaml file

is my test case.

All 7 comments

@cord Having nearly completed an entire site translation myself using Grav, I think this is an excellent idea.

Due to the performance enhancing decisions we made with the design of the multi-language support in Grav, this is really not possible. This is because Grav only knows about one language at a time, there's no way for Grav to look in 'parent' languages and 'merge' things.

Grav will fall back through the supported languages if a particular language file is not found, however, this really not the same because it only happens during the initial caching phase, and once a file is found, it's processed.

So ultimately this concern is one of performance. Having every single page parsing every other language file and merging is going to cause huge performance problems. I really can't see how this could be done efficiently. If you have any ideas i'm open to listen to them.

Hi Andy,

In my view grav would "only" need to look for default.meta.yaml and - if exists - read it and create the meta data structure before loading the language specific .md file which would then complete the meta data or eventually override settings.

There would be one default.meta.yaml file per page folder.

I agree with cord. Duplication of (meta) data is error-prone. A single meta data yaml would only have a minor performance penalty.

Ok, I created a PR for a solution to this. I made it a generic frontmatter.yaml file that was used so you could set any header (including metadata).

https://github.com/getgrav/grav/pull/775

IMPORTANT Please read my comments about the caveats of this: https://github.com/getgrav/grav/pull/775#issue-146441825

metadata:
    generator: 'Super Grav'
    description: from frontmatter.yaml file

is my test case.

Anyway, performance-wise this extra check added 3ms to my 100page test site (before caching).

Closing as the PR #775 was merged

Was this page helpful?
0 / 5 - 0 ratings