npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

fastify-ejs-page-builder

v1.0.2

Published

A litle tool to be used along side EJS and Fastify to allow you to inject variables to all your fastify routes. This is useful for injecting things like page meta data, page titles, etc. that are usually the same across all pages.

Downloads

1

Readme

fastify-ejs-page-builder

A litle tool to be used along side EJS and Fastify to allow you to inject variables to all your fastify routes. This is useful for injecting things like page meta data, page titles, etc. that are usually the same across all pages.

Usage

On your routes

import { PageBuilder } from 'fastify-ejs-page-builder';

// ... your code here

const page = new PageBuilder(`./src/webserver/pages/common/builder.ejs`); //This is the path to your builder file
page.setPageTitle('My Page'); 
page.setPageDescription('This is a great page');
page.setPageKeywords('page, great, awesome');
page.setPageNav(true);
page.setTheme('dark');
page.setCustomObject('myCustomObject', { foo: 'bar' }); //You can even set custom objects to be used in your common files as you like

return reply.render(page.getBuilderPath(), {

    page: page.getPage(),

    // ... your code here

});

Your page will now have available variables under the page object so you can do things like:

<head>
    <title><%= page.title %></title>
    <meta name="description" content="<%= page.description %>">
    <meta name="keywords" content="<%= page.keywords %>">
</head>

Functions

| Function | Description | | --- | --- | | setPageTitle(title: string) | Sets the page title | | setPageDescription(description: string) | Sets the page description | | setPageKeywords(keywords: string) | Sets the page keywords | | setPageNav(show: boolean) | Sets if the page should show the nav or not | | setTheme(theme: string) | Sets the page theme | | setCustomObject(key: string, value: any) | Sets a custom object to be used in your common files | | getPage() | Returns the page object | | getBuilderPath() | Returns the path to your builder file |

Page Object

Variables available in the page object (injected in ejs under page so you can use them like <%= page.title %>)

| Variable | Description | | --- | --- | | title | The page title | | description | The page description | | keywords | The page keywords | | nav | If the page should show the nav or not | | theme | The page theme |

Contributing

Feel free to open issues and pull requests. Currently I don't have any plans for this, mostly because it's just a class with a few functions, but if you have any ideas (like automatically injecting the page object in the reply.render function) feel free to open an issue or a pull request.

License

In LICENSE file.