DEV Community

Cover image for sherby-metadata
Benjamin Rancourt
Benjamin Rancourt

Posted on • Originally published at benjaminrancourt.ca on

sherby-metadata

Context

When I was coding the first versions of my bilingual website, I wanted the French and English versions, the only two pages I had, to appear correctly on search engines (SEO โ€“ Search Engine Optimization). I wanted to be able to search my name on Google and find my website (I know, I am a self-centered person ๐Ÿ˜‚).

To do that, I needed to update the meta data of the pages, which are data to help find the pages easily on the Web. They are primarily used by search engines to index correctly the pages on search results and by social media to add a preview of a link. ๐Ÿง

In HTML, meta data, also known as meta tags, are defined with a similar code as below for each page:

<meta name="description" content="One of these experiments was to start a personal blog, a place where I could freely write and mostly, deepen some things that I want to know or to remember better.">
<meta name="twitter:title" content="Introduction - Benjamin Rancourt">
<meta property="og:locale" content="en_CA">
Enter fullscreen mode Exit fullscreen mode
Example of meta tags from my previous post, Introduction

But, in the context of a Progressive Web App (PWA), I could not do that, as I had only a single HTML pageโ€ฆ So, I needed to find a way to update these tags dynamically inside my JavaScript application.

Creation

As my website was built with Web Components, I started looking into the WebComponents.org database to find one to manage meta tags inside my application. ๐Ÿ”

The only component that I found was the app-metadata element, from Captain Codeman. It had everything that I was looking for, but was built with the deprecated Polymer 1 libraryโ€ฆ

So, I decided to take inspiration from its work and to create a Polymer 2 component on my website. After some days (or maybe weeks), I could finally see on Google that everything was working as expected, as it takes some time for changes to propagate to the search engines. โณ

Screenshots of Google search results, on September 7, 2020

Publication

After a while, I decided that this component could be reusable to others and myself, so I finally published the first version (1.0.1 โ€“ August 20, 2017) on the Web under a new name: sherby-metadata. I could have made a Pull Request to its repository, but I did a lot of refactoring and added many comments to help me โ€“ and other people looking at the implementation โ€“ comprehend the source code. ๐Ÿ“–

I also wanted to experience the full publication of a Web Component, from GitHub to NPM.js, and the late WebComponents.org database. And with that, I have also experimented the writing of documentation and unit tests. ๐Ÿ“—

As the work of Captain Codeman helped me a lot, I added a credit into the README.md file to mention its component.

As the sherby-metadata component had been published in the NPM registry, I (almost) needed only to execute the command below to use it in my new website. It is really great to have this component published. ๐Ÿ˜Š

npm install @sherby/sherby-metadata
Enter fullscreen mode Exit fullscreen mode

History and future work

As my personal website has evolved, I refactored it to support Polymer 3 (2.0.0-rc.2 โ€“ May 11, 2018) and finally, LitElement (3.0.0 โ€“ July 7, 2019).

With the new use case of the component inside my blog, I encountered some corner cases that I will address someday, like support of multiple values for a tag (use case: article:tag and article:author), and the creation of a mixin, as there is nothing to render.

And while I am at it, I am sure there will be some maintenance work, like updating Node version and improving the documentation. ๐Ÿค–

So, there will probably be a 3.1.0 version soon. Watch the repository to be notified when the next release comes out. Or simply run npm-check-updates! ๐Ÿ˜‰ And if you use it, do not hesitate to star the project on GitHub! ๐ŸŒŸ

By chance, did you find this article by looking on a search engine? ๐Ÿ˜‰

Top comments (0)