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

astro-base-document

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

astro-base-document

Provide sensible defaults for HTML base document. The goal is to reduce boilerplate when using multiple layouts in Astro projects.

  • 1.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
Maintainers
1
Weekly downloads
 
Created
Source

🚀  Astro — Base document enclosure

NPM Downloads ISC License PRs Welcome

Astro TypeScript Prettier EditorConfig ESLint

Provide sensible defaults for HTML base document.
The goal is to reduce boilerplate when using multiple layouts in Astro projects.



📦  Installation

pnpm i astro-base-document

🛠  Usage

In your layout component, for example ./src/layouts/Default.astro:

---
import { Document, Body } from 'astro-base-document';

// ...
---

<!-- All properties are optional -->
<Document
  id="test-base-rootDoc"
  data-theme="default"
  lang="en"
  class:list={[`mode-${import.meta.env.MODE}`, 'my-class-html']}
>
  <Fragment slot="head">
    <!-- Things you can inject in `HEAD` -->
    <style is:inline>
      .some-class {
        color: red;
      }
    </style>
  </Fragment>

  <Body slot="body" id="my-id" class:list={['my-class-body']}>
    <!-- Things you can inject in `BODY` -->
    <nav>My navbar</nav>

    <!-- Your page content slot  -->
    <slot />
  </Body>
</Document>

🎉  Result

<!DOCTYPE html>
<html lang="es" class="some-class doby-doba js" id="the-id">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />

    <script>
      // CRITICAL
      // Add `js` class to `HTML` tag if JavaScript is enabled
      (() => {
        const root = document.documentElement;
        root.classList.add('js');
      })();
    </script>

    <style is:inline>
      .some-class {
        color: red;
      }
    </style>
  </head>

  <body class="other-class dabadi-dabada" id="much-id">
    <nav>My navbar</nav>

    <!-- Page content slot -->
    <div>My page content</div>
  </body>
</html>

The js class is added to HTML tag, critically.
That way, you can handle CSS for users with or without JS enabled with .js & / :not(.js) & SCSS selectors.

💈  Interface

/// <reference types="astro/astro-jsx" />

export interface Props extends astroHTML.JSX.HTMLAttributes {
  /**
   * **Default**: `'en'`
   * */
  lang?: string;

  /**
   * Provides early JS detection for further CSS use
   * by adding `js` class critically to HTML element.
   *
   * **Default**: `true`
   * */
  jsEnabledClass?: boolean;

  /**
   * **Default**: `null`
   * */
  redirectTo?: string | null;
}

LIVE DEMO  🎭  DOCUMENTATION WEBSITE ⎋

Live demo website

code.juliancataldo.com


Other projects:


🔗  JulianCataldo.com

Keywords

FAQs

Package last updated on 21 Jan 2023

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