Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

x-

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

x-

A toolkit for building static websites with reusable components and simple Markdown rendering

  • 0.7.0
  • unpublished
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

x- is a toolkit for building static websites with reusable components and simple Markdown rendering. Designed to be a natural extension of HTML, it can be used to quickly protoype and build a site from the ground up, or can be progressively integrated into an existing project with zero configuration. Using either the CLI or JavaScript API, everything is rendered to well-formatted, standard HTML, ready to be published.

Overview

Components

Components are created with a standard HTML file where properties can be defined with a basic template syntax:

<!-- src/components/greeting.html -->

<h1>Hello {{ name }}!</h1>

Components can then be used throughout a project with the <x-component> element, which should include a src attribute with the relative path to a component file ― the .html extension is implied. Property values are assigned with additional attributes on the <x-component> element:

<!-- src/pages/index.html -->

<x-component src="../components/greeting" name="world">

Components can also contain child content. The <x-slot> element is used to specify where content should be injected:

<html>
  <head>
    <title>{{ title }}</title>
  </head>
  <body>
    <main>
      <x-slot />
    </main>
  </body>
</html>

At build time, the <x-slot> element is replaced with any content inside the <x-component> element:

<x-component src="../components/base-layout" title="Home">
  <h1>Home</h1>
  <p>Page content...</p>
</x-component>

The <x-slot> element can contain optional fallback content that will be used if no child content for a component is provided:

<x-slot>Default content...</slot>

Markdown

Markdown rendering is available with the <x-content> element. Similar to <x-component> element, the src attribute is used to specify the relative path to a Markdown file:

<x-content src="../content/introduction" />

CLI

The CLI takes an input path to a file or directory and outputs compiled HTML files to ./public or the path specified with the --output option. If the provided input path is a directory, x- will recusively find and compile each HTML file in the given directory and its subdirectories. Any file or directory starting with an underscore (e.g., _components) will be ignored.

$ x- --help

Usage: x- <input> [options]

Options:

  -o, --output        Output path (Default: ./public)

  -v, --version       Print the current version and exit

Example:

$ x- src/pages --output static

API

render() reads the provided file and returns rendered HTML as a string:

render(filePath: string) => Promise<string>

Example:

const { render } = require('x-');

async function example() {
  const html = await render('index.html');
  console.log(html);
};

Installation

$ npm install --save-dev x-

Roadmap

  • Implement better HTML parser

    • The project is currently using regular expressions for parsing and manipulating HTML, which is often discouraged. Libraries like cheerio and jsdom seem a bit overkill and are noticebly less performant, but I'd like to look into lower level libraries like parse5 and htmlparser2.
  • Add named slots

  • Add file watching and automatic rebuilding with --watch CLI option

  • Add Node API

FAQs

Package last updated on 28 Oct 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc