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

@shaai/scroll-ink

Package Overview
Dependencies
Maintainers
2
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@shaai/scroll-ink

Ink template for Shaai

  • 1.1.14
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
2
Weekly downloads
 
Created
Source

Scroll

Ink

npm version

Scrolls

Scrolls (aka templates) are a pre-defined way of displaying data from Shaai. They are named as scroll-*, * being the name. Ink's npm package, hence, is @shaai/scroll-ink.

Usage

Shaai is a pluggable blogging framework, allowing you to use elements as per your need. All the scrolls use the @shaai/core package internally to source the blog data. According to your environment, you may use a scroll in following ways:

1. Using with React

Using Shaai with React is super easy, thanks to our React wrapper @shaai/react. Install the two dependencies required.

// You can replace scroll-ink with any other scroll of your choice

npm install --save @shaai/scroll-ink @shaai/react

And use them as follows:

import withShaai from '@shaai/react'
import ScrollInk from '@shaai/scroll-ink'

const Shaai = withShaai(ScrollInk)

const App = function(props) {
    return <div>
        <Shaai config={config} />
    </div>
}

const config = {
    // Described below
}

To include styles, add this line to your CSS file: @import "~@shaai/scroll-ink/dist/main.css"

2. Using with Vanilla JavaScript
  • Using in a Node dev environment

    To use in a Node project, install scroll-ink first.

    npm install --save @shaai/scroll-ink

    Then import and initialise it with the config object.

    import ScrollInk from '@shaai/scroll-ink'
    
    const s = new ScrollInk(config)
    
    // define your own templates
    const templates = [/* template array discussed below */]
    
    // Load whenever ready. If no templates are sent, Ink uses its default templates.
    s.load(templates)
    
    // Subscribe to updates
    s.subscribe((dom) => {
        let b = document.getElementById('blog')
        b.innerHTML = ''
        b.append(dom)
    })
    

    To include styles, add this line to your CSS file: @import "~@shaai/scroll-ink/dist/main.css"

  • Using in the browser To use Shaai in the browser directly, we recommend using unpkg to source the build files. Just include these lines inside your <head> tag of your HTML document.

    <link rel="stylesheet" type="text/css" href="https://unpkg.com/@shaai/scroll-ink/dist/main.css">
    <script src="https://unpkg.com/@shaai/scroll-ink/dist/main.js"></script>
    

    This will include the latest js and css build files from the scroll-ink npm package, which make the ScrollInk property available globally. The rest of the process is quite similar to the above one.

    let s = new ScrollInk(config)
    window.onload = function() {
        s.load()
        s.subscribe(function(dom) {
            document.getElementById('blog').innerHTML = ''
            document.getElementById('blog').append(dom)
        })
    }
    

Here's a short video to setup your first blog using Shaai and React.

Setting up your first blog

The config object

Each Shaai instance needs to be initialised with a config object to make Shaai work as the way you want. You can pass in following properties currently:

PropertyTypeDescriptionDefault
sourceobjectHas information about where to source the blog data fromrequired
basePathstringRelative path where your blog will rest e.g. /blog''
blogHeaderobject / HTMLElementData to be rendered in the blog header { title: 'My blog' }Default header
blogFooterobject / HTMLElementData to be rendered in the blog footer { title: 'Some text' }Default header
globalHeaderbooleanIf true, the header will be shown on all routes. Can be overriden at route level in the templates.false
globalFooterbooleanIf true, the footer will be shown on all routes. Can be overriden at route level in the templates.false
globalNavbooleanIf true, the nav bar will be shown on all routes. Can be overriden at route level in the templates.false
source object
PropertyTypeDescriptionDefault
namestringName of the data source CMS / FS / MEDIUM'CMS'
configobjectContains config data for the source e.g. { blogCode: 12345asdf } for source = 'CMS'required

Templates

Templates are the route-based views in scroll-ink. It is an array of template objects which have following properties:

path

This is the path/route for the template. Whenever the window path matches this value, the corresponding template will be rendered.

fetch

This is the method which is called before rendering the respective view. It receives the shaai instance, the store and the url params. While most views would requiring fetching data, you can skip this property if only static data has to be rendered.

template

This is the function that returns the actual DOM snippet for the matched path. It receives the data received from the fetch function, if any, and should return a HTMLElement object.

name

This property is used at places like the navigation bar, to mention the matched path's name.

A template object can look as below

const templates = [
    {
        path: '/',
        name: 'Posts',
        template: (data) => s.list(data, { minimiseContent: true, viewFilter: ['title', 'content', 'publishData'] }),
        fetch: (shaai, store, params) => {
            return new Promise(res => {
                if(store.getData('posts')) {
                    res(store.getData('posts'))
                }
                shaai.getBlogs().then(data => {
                    store.setData({ posts: data.items })
                    res(data.items)
                })
            })
        }
    },
    {
        path: '/about',
        name: 'About',
        template: ({ config }) => {
            let html = `
                <div>
                    <h4 class="about-heading">About me</h4>
                    <p class="about-content">Hello there! I am <a href="https://github.com/mohtik05">@mohitk05</a></p>
                </div>
            `
            let about = document.createElement('div')
            about.className = 'about'
            about.innerHTML = html

            return about
        }
    }
]

Development

Run npm run start:dev for starting the Webpack dev server.

Keywords

FAQs

Package last updated on 04 Sep 2019

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