Git Product home page Git Product logo

next-with-authored-pages's Introduction

Next.js sample app with page authoring integration

Assumption: Page information available through a sample page service - and dynamically importing required components We can create a mapper to transform service response to required structure assumed.

Getting Started

Clone this repo and run following for development mode:

npm install
npm run dev
# or
yarn
yarn dev

Run the mock server separately (which serves the page services):

npm run mock-server
# or
yarn mock-server

For production mode (all with mocks for now):

npm run build:serve
# or
yarn build:serve

The idea behind the example

This examples shows how to dynamically import modules via import() API and futher extend it to a use case where the page layouts are governed by an external CMS.

Concepts/Assumptions:

  • Sections: Horizontal rows
  • SubSections: Columns inside the rows

Page service response structure:

{
  "type": "sections",
  "layout": {
    "sections": [
      {
        "id": "111", //identifier for the section,
        "type": { // subsection column division inside the section [details above] assuming a 12-column for section
          "bleed": true // this is a case where it is full bleed
        },
        "modules": [
          [
            {
              "id": "hello1-1", // component identifier
              "name": "hello1" // component name
            }
          ]
        ]
      },
      {
        "id": "222",
        "type": {
          "columns": [ // column divisions by viewports
            { // for hello2 component
              "lg": 4,
              "md": 6,
              "sm": 12,
              "xs": 12
            },
            { // for hello5 component
              "lg": 4,
              "md": 6,
              "sm": 12,
              "xs": 12
            },
            { // for hello4 component
              "lg": 4,
              "md": 6,
              "sm": 12,
              "xs": 12
            }
          ],
          "offsets": [] // column divisions by viewports - same format as above
        },
        "modules": [
          [
            {
              "id": "hello2-1",
              "name": "hello2"
            }
          ],
          [
            {
              "id": "hello5-1",
              "name": "hello5"
            }
          ],
          [
            {
              "id": "hello4-1",
              "name": "hello4"
            }
          ]
        ]
      },
      ...
    ],
    "contexts": { // contexts to be passed to the components
      "page": {
        "global": {
          "pageId": "page-1",
          "name": "home",
          ... // more page level context
        },
        ... //more global context
      },
      "modules": {
        "hello1-1": { // by ID
          "data": {
            "prop1": 1,
            "prop2": "hello1",
            ... // more hello1 component context
          }
        },
        ... // contexts for more components
      }
    }
  }
}

Important files

  • Application Layout Component: pages/_app.js
  • Base Rendering Engine (for all routes): pages/BaseLayoutEngine.js
  • Component Registry: components/lib/componentRegistry.js
  • Layout Renderer: components/lib/renderers/layoutRenderer.js
  • Page Service Mocks: mocks/page-service

Self-signed certificates under certificates/ for running http2 server. [Can be removed later]

Bundle Analyzer

You can run one of these commands:

# Build and analyze the back end server bundle
BUNDLE_ANALYZE=server yarn build

# Build and analyze the front end browser bundle
BUNDLE_ANALYZE=browser yarn build

# Build and analyze both server and browser
BUNDLE_ANALYZE=both yarn build

# Build and analyze neither server nor browser
yarn build

If you choose both then two different browser windows will open. One will be for the server bundle, one for the browser bundle.

next-with-authored-pages's People

Contributors

rakeshmenon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  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.