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:
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. โณ
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
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)