GithubHelp home page GithubHelp logo

davbree / best-olive-copy-01 Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 2.18 MB

Jamstack site created with Stackbit

Home Page: https://jamstack.new

JavaScript 100.00%
jamstack stackbit ssg headless static nextjs git

best-olive-copy-01's Introduction

Stackbit Nextjs V2

A Nextjs page builder, component library and data fetcher.

Quickstart

npm install
npm run dev

How It Works

Content

Content is sourced from the filesystem using Sourcebit. It loads markdown and json files stored in content/pages and content/data and tranforms them into page objects which are used by getStaticProps().

  • This theme comes with a pre-configured sourcebit config sourcebit.js
  • This theme comes pre-configured to use sourcebit.fetch() in the next.config.js
// next.config.js

const sourcebit = require('sourcebit');
const sourcebitConfig = require('./sourcebit.js');

sourcebit.fetch(sourcebitConfig);

module.exports = {
  ...
}

Whenever you run npm run dev or npm run build Sourcebit fetches content and outputs the .sourcebit-nextjs-cache.json file which contains an array of page objects.

Inside a Nextjs page route like src/pages/[[...slug]].js you can load page data by it's path using the sourcebitDataClient.getStaticPropsForPageAtPath(path) function inside of getStaticProps

// src/pages/[[...slug]].js

export async function getStaticProps({ params }) {
  const props = await sourcebitDataClient.getStaticPropsForPageAtPath(params.slug);
  return { props };
}

Components

This theme uses the Stackbit component library

  • This theme comes pre-configured to use withStackbitComponents() in the next.config.js
// next.config.js

const withStackbitComponents = require('@stackbit/components/with-stackbit-components');

module.exports = withStackbitComponents({
  componentsMapPath: '.stackbit/components-map.json',
  ...
})

withStackbitComponents generates a dynamic import map for the Stackbit component library. This provides a framework to override existing Stackbit components and add your own new components. This approach reduces the bundle size by only importing components that are used.

  • Generates .stackbit/components-map.json - Edit this file to override or add new components
  • Generates .stackbit/dynamic-components.js - This file is dynamically generated from components-map.json and should not be edited or committed to git.

You can now use getDynamicComponent(ComponentName) in a Nextjs page.

// src/pages/[[...slug]].js 
import { getDynamicComponent } from '@stackbit/components/components-registry';

function Page(props) {
  console.log(props);
  const { page, site } = props;
  const { layout } = page;

  const PageLayout = getDynamicComponent(layout);

  return <PageLayout page={page} site={site} />;
}

Tailwind

You can edit the tailwind config in tailwind.config.js

The Stackbit component library includes a number of preset Tailwind themes which you can use.

// tailwind.config.js

module.exports = {
  presets: [require('@stackbit/components/themes/tailwind.bold.config')],
  mode: 'jit',
}

best-olive-copy-01's People

Contributors

stackbit-projects avatar

Watchers

James Cloos avatar David Berlin 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.