Writing documentation has become easy thanks to VuePress
Wojciech Bak
Writing documentation is a standard that in many projects becomes a luxury. Its production easily goes into the background, especially when the next priority is given to the further functionalities at the phase of dynamic application development.
It has always been an important issue to make an effort necessary to design, program and implement something that meets several criteria:
allows you to quickly get to the structure of an application
allows you to freely search the content
provides a set of technical information on the used solutions
can be stored on GitHub, preferably with a possibility of easy deployment.
No wonder that the documentation is associated with large expenses. On the other hand, the team is growing, onboarding generates a lot of costs, and for that support constantly asks developers the same questions. At some point, everyone is missing … VuePress.
VuePress is a static page generator based on the Vue.js framework, which is great for creating documentation. A good example can be set by the documentation of Vue.js itself.
VuePress allows you to edit texts in the Markdown format with the usage of Vue components, which, finally, give a really wide range of possibilities. Just start with two commands:
npm install -g vuepress
vuepress dev
By default, VuePress runs on the docs / directory and creates its own. vuepress folder in it. After entering the above commands, it automatically starts the Node server and displays the documentation at localhost: 8080 /. Here is an example of the file structure.
With a proper configuration, VuePress will generate a complete and very aesthetic page. As you can see on the screen above, our documentation contains two custom components – CodeHeading and ColorSample.
A simpler example for the beginning will be CodeHeading.
This is a standard syntax of a Vue.js component, which is easily available in Markdown files. Here’s an example of an implementation (/docs/Code/javacript.md):
In this way, we have received a completely legible solution to present examples of working with a code.
Probably every frontend developer has had a situation where they lacked the HEX representation of any colour from the graphics design. And what if you could always have colour at hand and fix a certain palette in advance? That’s right – documentation somehow makes us stick to the standard. The result may look like the following:
In this example, the ColorPicker.vue component was used. It serves not only the presentation of a given colour – by clicking on a circle, we will automatically copy the HEX code to the clipboard.
Template:
<template>
<div class="color-sample">
<div class="color-sample__container">
<div
class="color-sample__circle"
@click="copyToClipboard"
:style="`background-color: ${ color }`"
title="Click to copy HEX code"
>
<div class="color-sample__input-wrapper">
<input type="text" class="color-sample__input" :id="hexId" :value="color">
<div class="color-sample__input-overlay" :style="`background-color: ${ color }`"></div>
</div>
</div>
<p>
<strong>(( name ))</strong><br/>
(( color ))
</p>
</div>
</div>
</template>
With the vuepressbuild command, we can instantly generate static HTML files ready for quick publication with full asset support.
It is worth mentioning that VuePress allows an automatic deployment on various platforms, including GitHub Pages. In addition, the ability to create your own themes makes VuePress quite a good blog solution.
If the above examples aroused your curiosity, for more information I recommend you to get acquainted with official documentation of the VuePress project.