GithubHelp home page GithubHelp logo

wjohnsto / simple-site Goto Github PK

View Code? Open in Web Editor NEW
49.0 3.0 3.0 2.35 MB

Boilerplate for a simple yet heavily-optimized website

License: MIT License

JavaScript 9.53% CSS 7.63% TypeScript 49.95% HTML 32.89%

simple-site's Introduction

Website Boilerplate

Are you looking to build a website that is easily updatable/maintainable? Do you hate Wordpress and other bloated website platforms? Do you understand that simple websites do not require the use of a SPA framework? Do you still want to needlessly optimize your site to the nth degree, and get a 100 on Google PageSpeed? Well this is the project for you.

You can see a working demo of this project here.

Getting Started

So you're ready to build an awesome new website. Good, this is the place to be. This project helps you setup a site using Bootstrap 4, TypeScript, SASS, Handlebars, NodeJS/Express, Markdown, and a few optimizations for serving webp, AMP, bundling js/css, inlining js/css, and helping with SEO/Structured Data.

Layout

The site has the following directories

  • build: Contains some build scripts for running the server
  • public: Where all the public assets go. Note that the CSS and JS folders will be created automatically by the build process.
  • scss: Where you put all your SASS files.
    • includes: Used for global styles, bootstrap overrides, etc
    • layouts: Used for main layout styles
    • partials: Used for partial layout styles
  • server: Contains all the files necessary to run the server
    • blogs: Put all your blog markdown here
    • config: Stores global configuration for the server
    • helpers: Stores handlebars helpers
    • log: A simple logging utility class
    • middleware: Has files for CORS, errors, setting meta context, serving webp, handling redirects, and parsing/compiling Handlebars files
    • routes: Defines all the pages for the site
    • typings: Adds some types to the project
    • utils: Has utility methods and a caching class
  • ts: Where you put all your TS files.
    • layouts: Used for TS scripts that can be included in many pages
    • partials: Used for TS scripts that need only be included in specific pages
  • views: Where you put all your Handlebars files for your pages.
    • layouts: Used for Handlebars layout pages
    • partials: Used for Handlebars partials

Features

Here are a few cool things this project is designed to do.

Webp

The express server can serve webp assets alongside pngs and jpgs. So in your html you might have <img src="path/to/image.jpg">, and if the server finds a file path/to/image.webp it will serve it instead.

AMP

This project comes with blog scaffolding for you, which includes an AMP template. If you run the project and go to any blog post, you can see the AMP version by visiting the blog <url>/amp.

Build Process

The build process includes a few custom scripts in the build directory. There is a minify script that will compile and minify TypeScript files and output to a public JS directory. There is also a lib build script that will build 3rd-party libraries for you and output to a public/js/lib.js. By default it builds bootstrap and its dependencies (jQuery, popper, etc). The last script is the scss script. This will compile your SASS files (in the scss directory) per-page. So you don't have to worry about including unnecessary css per page, and you also don't have issues with overriding styles.

Inlining Styles and Scripts

When this project was created, the intention was to perform all optimizations to make the site as fast as possible while allowing for ease of deployment. The express server is designed to allow you to declare styles and scripts that you with to inline with your HTML pages. If you put the following in a .hbs page:

<!-- Remove Script -->
<script src="/public/lib/lib.js"></script>
<!-- /Remove Script -->

<!-- Remove Style -->
<link rel="stylesheet" href="/public/css/about.css">
<!-- /Remove Style -->

There is a method that runs after the Handlebars page is rendered. It pulls out the scripts and styles, concatenates them, and then puts them in 1 style or script tag. After that it caches the pages to save some time with multiple requests. Of course there are times when you don't want to concatenate the styles/scripts. You can do so using an "ignore" attribute like so:

<link ignore="true" href="https://fonts.googleapis.com/css?family=Lato:100,300,400,700,900" rel="stylesheet">

Read Time

There is a simple reading time calculator for blog posts, which can help entice users to read a post knowing that it should only take 3-5 minutes.

SEO

This project has example structured data that you can replace with your own properties. There is structured data for an Organization, Breadscrumbs, and Articles. It's also designed to allow you to specify title, description, image, and video meta information for every page when you add a new route.

Markdown Front Matter

You will notice in server/blogs there are blog markdown files. They include some front matter that has information about the blog. The server interprets this and sets the right context when rendering a page.

Prerequisites

The only requirements to build this project are Node and npm.

Installing

Setting up this project is incredibly simple:

npm install
npm run lib
npm run dev

Then navigate to http://localhost:3000/ and see a sample mini-site built out for you.

NOTE: You only need to run npm run lib whenever you change the lib.js in /build, or when one of the libraries updates.

Adding a Page

When you want to add a page, there are a couple things to do:

  1. Create a new Handlebars file in views
  2. Create a new route in server/routes
  3. Add the route to the Express router in server/routes/index.ts

Useful NPM Scripts

  1. build: Builds everything (srver, client, lib, and sass)
  2. clean: Cleans the compiled files
  3. dev: Run this in dev mode, watches files and starts a dev server
  4. format: Runs prettier to format all the TS files according to the prettier.config.js
  5. lint: Runs tslint using the tslint.json, also uses some addons from tslint-microsoft-contrib
  6. start: Starts node server

Deployment

This site can be deployed on AWS, GCP, Azure, Heroku, etc. I didn't include any deployment instructions, so you will have to figure that part out on your own.

Built With

  • Express - Used to render pages and serve assets
  • Bootstrap 4 - Used for the easy layout, duh
  • Handlebars - Used to render pages and apply simple context
  • Remarkable - Used for markdown rendering on blog pages
  • TypeScript - Used to allow you to write simple scripts in TypeScript that will be included with your pages
  • SASS - CSS precompiler

Demo

You can see a working demo of this project here.

Authors

  • William Johnston - Initial work - wjohnsto

Contributors

License

This project is licensed under the MIT License - see the LICENSE.md file for details

simple-site's People

Contributors

wjohnsto avatar dependabot[bot] avatar veggiedefender avatar

Stargazers

Philipp avatar Roman Hossain Shaon avatar Theofanis Despoudis avatar Rozay avatar A. Rodriguez avatar Ramón Souza avatar Matt Coston avatar Tadeusz Dudkowski avatar Tyler avatar John Datserakis avatar Nicholas Colletti avatar Jackson Carr avatar Krittanan Pingclasai avatar Pranav avatar Chance Smith avatar Etienne Maheu avatar ɹǝʞɹɐԀ uǝʌS avatar Eric Dockter avatar Robert Guss avatar Vishal Isharani avatar Aaron avatar Chris Hall avatar  avatar Brooke Appe avatar Anthony Rudny avatar Alex Myers  avatar Mihai Popa avatar  avatar  avatar Tucsky avatar Animesh Bulusu avatar  avatar Christian Teobaldo avatar Tuomas Ukkola avatar Daniel avatar  avatar Atkos avatar Christian Piper avatar  avatar Justin Loyed avatar  avatar Matt Welson avatar  avatar Igor Krstevski avatar Spenser X avatar Seth Rujiraviriyapinyo avatar  avatar Erick Olivares avatar Tyler Gaw avatar

Watchers

James Cloos avatar Atkos avatar Matt Coston avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.