website-v2 icon indicating copy to clipboard operation
website-v2 copied to clipboard

bug(preview): Empty title in content causes no title tag

Open btkostner opened this issue 4 years ago • 1 comments

This is a bug in Docus but the repo isn't public so I'm not sure where I should report it.

Issue

content/en/index.md has no title property set, and therefor has no title tag being rendered.

Fix

In docus file core/module.js has a line like:

      document.title = document.to.split("/").pop().split(/[\s-]/g).map(pascalCase).join(" ");

and should be updated to include:

      document.title = document.to.split("/").pop().split(/[\s-]/g).map(pascalCase).join(" ") || null;

that way it falls back to the default nuxt title.

You will also want to change the pageMeta function to something like this in app/pages/_.vue:

    pageMeta() {
      return [
        /// Page title
        ...(this.page.title
          ? [
            // OpenGraph
            {
              hid: 'og:title',
              property: 'og:title',
              content: this.page.title
            },
            // Twitter Card
            {
              hid: 'twitter:title',
              name: 'twitter:title',
              content: this.page.title
            },
          ]
          : []),
        /// Page description
        ...(this.page.description
          ? [
              // Meta description
              {
                hid: 'description',
                name: 'description',
                content: this.page.description
              },
              // Open Graph
              {
                hid: 'og:description',
                property: 'og:description',
                content: this.page.description
              },
              // Twitter Card
              {
                hid: 'twitter:description',
                name: 'twitter:description',
                content: this.page.description
              }
            ]
          : [])
      ]
    }

Alternative fix

Use the docus.config.ts title and description as fallback for all metadata.

Random thoughts

I was wondering why this site was made with docus instead of @nuxt/content til I found the magic with social-image, twitter, and admin. Looking forward for the repo to be public so we can hopefully port some of that awesomeness to other projects (or separate modules)! :confetti_ball: :partying_face:

btkostner avatar Jul 10 '21 19:07 btkostner

@btkostner Thanks for the report and sorry for the delay :grimacing:

@Tahul This seems good for nuxtjs.org, do you need to take note of this? I'm about to close it.

smarroufin avatar Sep 27 '21 13:09 smarroufin