# MetaStatic Tutorial
### Building a Web Site Using the SB Admin Meta Tag Library
# Introduction
The MetatStatic Repository includes a Tag Library that provides a partial implementation of the Open Source [SB Admin](https://github.com/StartBootstrap/startbootstrap-sb-admin) User Interface. What's included is sufficient to demonstrate:
- how a technical developer can build out such a Meta Tag Library
- how a Web Site maintainer can build and maintain a site using such a Tag Library
In this tutorial we'll explain in detail both aspects so that by the end of the tutorial you can begin to use MetaStatic for your own specific purposes.
# Getting Started
MetaStatic is written in JavaScript and therefore requires either Node.js or Bun.js to run.
In this tutorial I'm going to use Bun as it's a lot faster to run and much simpler to set up and maintain than Node.js, but if you're a Node.js developer it should be straightforward to translate the instructions to make them work with Node.js.
This tutorial also assumes that you'll be using a Linux machine. Bun.js is also available for Windows and MacOS and once installed, all the commands should work identically apart from file path syntax differences.
So let's get started!
## Create a Work Directory
Create a directory for this tutorial and switch to it.
For example:
```code
mkdir mstutorial
cd mstutorial
```
## Install Bun.js
If you're using Linux or MacOS, the recommended way to install Bun.js is as follows:
```code
curl -fsSL https://bun.sh/install | bash
```
If you're using Windows, [refer to the Bun.js documentation](https://bun.sh/docs/installation).
## Clone the MetaStatic Repository
```code
git clone https://github.com/robtweed/metastatic
```
## Switch to the Repository's */examples* directory
cd cd metastatic/examples
## Start the Included Bun.js Web Server
We've included a basic but handy Web Server. It's written in Bun.js and uses its extremely fast *Bun.serve* HTTP server. This Web Server will allow you to quickly view the Web Site file(s) you generate in this tutorial directly from the location in which MetaStatic will create them.
Note that this Web Server is **NOT** meant for production use!
You'll see the Bun Web Server in the directory that you've previously switched to:
```code
bunws.js
```
and you can [view its source code here](./examples/bunws.js).
Note also that the file(s) generated by MetaStatic can be served up by any Web Server, so once you're happy with them, simply upload them to your Web Server. You will, of course, need to ensure that any URL paths for images etc that you might use are correctly structured for your production Web Server.
To start the Web Server, just issue the following command from the */examples* directory:
```code
bun bunws.js
```
This will start the Web Server and it will listen on port 3000. If you're already using that port for something else, Bun will report an error and fail to start. If so, you can specify a different port, eg:
```code
bun bunws.js 8080
```
Note: the first time you invoke this command, Bun should automatically install all of the Web Server's dependencies. If it doesn't, and if it reports an error, eg:
```code
error: Cannot find package "mg-bun-router" from "/home/ubuntu/metastatic-tutorial/bun/metastatic/examples/bunws.js"
```
Then try manually installing the missing package:
```code
bun install mg-bun-router
```
You should then be able to start the Web Server.
## Test the Web Server
The Bun Web Server is automatically configured to fetch static files from the */examples/sites* folders. You can test it with the *demo* site which includes a pre-built *index.html* file. In another process, type:
```code
curl http://localhost:3000/demo/index.html
```
or point a browser at this same URL.
if you followed the instructions correctly, you should see the file's contents or see them rendered in your browser.
If so, you're ready to begin exploring MetaStatic!
----
# The SB Admin Tag Library
## Background
You'll find the SB Admin Tag Library in your */examples/metaTagLibraries/sbadmin* directory.
You can also see the [source files here](./examples/metaTagLibraries/sbadmin).
The SB Admin User Interface (UI) is designed around a set of panels:
- a top bar, for titles etc
- a left-hand panel for menu options
- a footer panel for site information, copyright notices etc
- a main content panel
This UI is based on the popular Open Source responsive Bootstrap v5 CSS framework. The built-in responsive behaviour is very nice: for example, you'll find that the menu panel will automatically collapse on small devices such as phones, and content will automatically stack vertically in small devices.
As such, the SB Admin UI is very powerful and versatile and can be used for many, if not most Web Sites to provide a modern UI for your content.
Of course, with MetaStatic you aren't limited to using this UI: any alternative UI can be implemented as a set of MetaStatic's Meta Tags and then used to construct your Web Site. Their design is entirely up to you!
The *namespace* we've used for the SB Admin Tag Library is *sbadmin*, so you'll notice that all the individual Tag definition files are prefixed with this, eg:
- sbadmin-root
- sbadmin-header
- sbadmin-sidebar-menu
Each Meta Tag is defined in its own file which has a file extension of *.mst*, eg:
- sbadmin-root.mst
- sbadmin-header.mst
- sbadmin-sidebar-menu.mst
A Web Developer/Maintainer will use these as tags, eg:
- <sbadmin-root>
- <sbadmin-header>
- <sbadmin-sidebar-menu>
## The Root Meta Tag
Every MetaStatic Tag Library will have a top-level tag within which all other Tags are nested. What it's called is up to you. In our case we've named this tag *sbadmin-root*.
You'll find it in your system at */examples/metaTagLibraries/sbadmin/sbadmin-root.mst*.
You can also inspect its [source code here](./examples/metaTagLibraries/sbadmin/sbadmin-root.mst).
We'll come back to explain its contents and how/why it works in detail later.
For now, suffice to say that this Meta Tag:
- creates the correct HTML <head> tag contents for your Web Site:
- loading the required Bootstrap-compatible CSS resources;
- loading the Bootstrap JavaScript resources
- loading the free Font Awesome icon resources
- adding some specific customisable styles that override the standard *StartBootstrap* ones
- defines and creates the basic UI layout in the <body> tag
## Creating Our Web Site
Let's get started and create a "bare bones" SB Admin Web Site.
Change to the */examples/sites/tutorial* directory that you'll find on your system.
In order to create a Web Site, you create a file with a file extension of *.meta*. The file name is otherwise up to you, but by convention, a single page Web Site will normally have a name of *index*.
You'll find we've already created an instance of the *index.meta* file for you to get you started. It's very simple and just contains the *sbadmin-root* tag:
```html