Livingdocs minimal example

node v8.17.0
version: 1.0.0
endpointsharetweet
/* The reference design and content-types here are for the Sandbox (magazine example). If you want to use this code with a different Livingdocs design make sure to customize the design and searched content-type. */ const liSDK = require('@livingdocs/node-sdk@0.5.1') const liClient = new liSDK.Client({ url: 'https://server.livingdocs.io', accessToken: null // TODO: add your access token from `edit.livingdocs.io` by navigating to `Access Management` -> `Api Tokens` }) const publications = await liClient.search({contentType: 'article'}) if (!publications || publications.length === 0) { console.error('There seems to be something wrong with your project setup. Please make sure you have a homepage in Livingdocs') return } const randomPublication = publications[0] // This has to match the used image service, which for edit.livingdocs.io will always be `liImageProxy` // You can customize the srcSet image sizes for your use case. const config = { imageServices: { liImageProxy: { host: 'https://server.livingdocs.io', preferWebp: true, backgroundImage: { maxWidth: 2048 }, srcSet: { defaultWidth: 1024, widths: [2048, 1024, 620, 320], sizes: ['100vw'] } } } } const axios = require('axios') const designRes = await axios.get('https://api.livingdocs.io/designs/living-times/1.0.2') const livingdoc = liSDK.document.create({ design: designRes.data, content: randomPublication.content, config }) const html = liSDK.document.render(livingdoc) console.log('html', html)
Loading…

no comments

    sign in to comment