I'm using Firebase & Vue to create a dynamic site. One section of the site will contain hundreds of article pages in the form:
<article>
<!-- order of these elements will not change -->
<h1>Article title</h1>
<div id="date">1/1/2021</div>
<div id="author">Author</div>
<div id="tags">Tag1, Tag2, Tag3</div>
<div id="content">
<!-- order of elements varies based on needs of article. sample elements below -->
<h2 class="subtitle>Subtitle 1</h2>
<p class="text"><span class="smallcaps">Lorem ipsum dolor</span> sit amet, consectetur adipiscing elit, <a href="https://example.com/">link</a>.</p>
<blockquote>"An embedded tweet"</blockquote><script async src="https://platform.twitter.com/widgets.js"></script>
<h2 class="subtitle>Subtitle 2</h2>
<p class="text">Excepteur sint occaecat cupidatat non:</p>
<figure><img src="img.jpg"/><figcaption>Caption</figcaption></figure>
<h2 class="subtitle>Subtitle 3</h2>
etc...
</div>
</article>
<!-- comments feature below -->
In terms of storing the article content, I've come across three options, none of which seem ideal:
Store the HTML tags and content within
<div id="content">
inside a field in each article's Firebase document, then useinnerHTML
to inject the contents of that field into<div id="content">
. Use oneArticle.vue
file to pipe in and display eacharticle
document from the Firebase collection. While this is easy and solves my problem, I'm afraid of XSS attacks, especially since I'll sometimes be using<script>
to embed content from social media sites like Twitter and YouTube.Create a field in Firebase for each HTML element that I expect within the article (e.g.,
subtitle1
,paragraph1
,blockquote1
,subtitle2
,paragraph2
, etc.). Use oneArticle.vue
file to pipe in and display an article's elements. I already planned to do this with the standardized elements, liketitle
,date
, andauthor
, but doing so for elements within<div id="content">
would remove variability in the structure of the articles. Even dealing with external links (i.e.,<a href="https://example.com/">
) within paragraphs would be painful, if not impossible.Make a separate
.vue
file for each article. This allows for full customization of each article, but doesn't scale well with hundreds or thousands of articles.
Is there a better option, or am I stuck with one of these three? I'd prefer not to install CMS software like WordPress in order to keep a consistent feel to my site.