Product
Introducing SSO
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
content-structure
Advanced tools
Readme
content-structure collects all your markdown files meta data and parses the Abstract Syntax Tree of each file
! note this project is just starting and is not yet generating all planned artefacts, minor versions can still have breaking changes !
npm install content-structure
collect all data by running this once
import {collect} from 'content-structure'
await collect()
then use as follows
import {getDocuments, getEntry} from 'content-structure'
const documents = await getDocuments()
console.log(`obtained ${documents.length} documents`)
const authors = await getDocuments({content_type:"authors"})
console.log(`found ${authors.length} authors`)
const generic_markdown = await getDocuments({format:"markdown",content_type:"generic"})
console.log(`found ${generic_markdown.length} generic markdown entries`)
const image_entry = await getEntry({slug:"image"})
const images_urls = image_entry.data.images.map(image=>image.url)
console.log(`'image' content entry has following images '${images_urls}'`)
will output
obtained 14 documents
found 3 authors
found 11 generic markdown entries
'image' content entry has following images './tree.svg,./long-diagram.svg'
Content type is a field existing in every document as content_type
. For a hierarchically structured content, the content type can be derived from the parent folder, and can in all cases be overridden by the user when defined in the meta data (markdown frontmatter or content of json or yaml)
content_type
field in data => taken from dataThe "generic" content type is the default assignment when no parent and no manual type is provided, the genric type does not get included in the uid definition
The content type, like any other field, can be filtered as follows
const authors = await getDocuments({content_type:"authors"})
see also the following section for an author
content_type example.
Content structure allows both file and folder URL types to be used at the same time without the need of user configuration. The convention is the basename of the file, in case it is readme
for markdown or entry
,document
for json or yaml, the URL will be considered as folder, and file for any other filename.
All of the three files below will automatically generate a filed content_type
of the parent folder authors
if not otherwise specified inside the json or yaml files.
───content
├───authors
│ │ myself.json
│ │ stephen-king.yaml
│ └───agatha-christie
│ entry.yml ...
the field url_type
will also be exposed for the user as in the example entry below
{
"sid": "a518c9b7",
"uid": "authors.agatha-christie",
"path": "authors/agatha-christie/entry.yml",
"url_type": "dir",
"slug": "agatha-christie",
"format": "data",
"content_type": "authors",
...
}
the config parameter is optional and do have default values
rootdir
: defaults to current working directory. The path where to find the a content
directory.rel_outdir
: defaults to gen
. Relative output directory is the location where all output data will be generated, which is relative to the root directory.gen/document_list.json
./gen/documents/<sid>
directors with
tree.json
the raw output of the remark AST parserthis files structure
└───content
├───title-complex
│ readme.md
├───text-simple
│ readme.md
...
generates this output
└─gen
│ document_list.json
└───documents
├───35298154
│ content.json
│ tree.json
├───12b0e722
│ content.json
│ tree.json
...
document_list.json
is the documents index[
{
"sid": "35298154",
"uid": "title-complex",
"path": "title-complex/readme.md",
"url_type": "dir",
"slug": "title-complex",
"format": "markdown",
"title": "title Complex",
"content_type": "generic"
},
{
"sid": "12b0e722",
"uid": "text-simple",
"path": "text-simple/readme.md",
"url_type": "dir",
"slug": "text-simple",
"format": "markdown",
"title": "Text Simple",
"content_type": "generic"
},
...
---
title: Image
---
![Tree](./tree.svg)
example of generated files for image/readme.md
which has an sid of 78805a22
{
"sid": "78805a22",
"uid": "image",
"path": "image/readme.md",
"url_type": "dir",
"slug": "image",
"format": "markdown",
"title": "Image",
"content_type": "generic",
"headings": [],
"tables": [],
"images": [
{
"id": "tree",
"heading": null,
"title": null,
"url": "./tree.svg",
"alt": "Tree",
"label": ""
}
],
"code": [],
"paragraphs": [
{
"heading": null,
"label": []
},
{
"heading": null,
"label": []
}
]
}
and the beginning of tree.json
{
"type": "root",
"children": [
{
"type": "paragraph",
"children": [
{
"type": "image",
"title": null,
"url": "./tree.svg",
"alt": "Tree",
"position": {
"start": {
"line": 1,
"column": 1,
"offset": 0
},
...
FAQs
Content Structure collect all your markdown files meta data and parses the Abstract Syntax Tree of each file
The npm package content-structure receives a total of 390 weekly downloads. As such, content-structure popularity was classified as not popular.
We found that content-structure demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Product
Streamline your login process and enhance security by enabling Single Sign-On (SSO) on the Socket platform, now available for all customers on the Enterprise plan, supporting 20+ identity providers.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.