Skip to content

Commit

Permalink
Docs
Browse files Browse the repository at this point in the history
  • Loading branch information
benmerckx committed May 4, 2022
1 parent 0f766ea commit 9c9ffbe
Show file tree
Hide file tree
Showing 17 changed files with 530 additions and 44 deletions.
52 changes: 52 additions & 0 deletions apps/web/content/data/docs/configuration/fields/check.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"id": "28htwzY7qMeaV15j276Myvpek8y",
"type": "Doc",
"root": "data",
"index": "a3V",
"title": "Check",
"blocks": [
{
"id": "28htxzGsXQK0zKnFg9SC9JziC80",
"index": "a0",
"type": "TextBlock",
"text": [
{
"type": "heading",
"level": 1,
"content": [
{
"type": "text",
"text": "Check"
}
]
},
{
"type": "paragraph",
"content": [
{
"type": "text",
"text": "A check field is used to input boolean data."
}
]
},
{
"id": "28hu0MbpUcAOhWTWi954kRRNHcM",
"type": "CodeBlock",
"code": "check('My check field', {\n help: 'This is an example check field'\n})",
"compact": true
}
]
},
{
"id": "28hu4zpW1YdyW9MM76mD627dl6n",
"index": "a1",
"type": "TypesBlock",
"types": "CheckOptions"
}
],
"parents": [
"docs",
"259Ey7LXgqL7ZDGJ8XK1vBJmZrh",
"24yE2mu6Xq959jrP135Sdb4e3lG"
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@
"type": "Docs",
"root": "data",
"index": "ZoG",
"title": "Fetching data"
"title": "Content",
"parents": [
"docs"
]
}
103 changes: 103 additions & 0 deletions apps/web/content/data/docs/content/introduction.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
{
"id": "28Ng6ZnpyhafrKdGMOO7BUUKP4S",
"type": "Doc",
"root": "data",
"index": "a0",
"title": "Introduction",
"parents": [
"docs",
"28Ng5RzmZ2fHUVlVbAEv1l1oUUS"
],
"blocks": [
{
"id": "28Ng8SpEKCBCaddO8Zeiy3CSUHl",
"index": "a0",
"type": "TextBlock",
"text": [
{
"type": "heading",
"level": 1,
"content": [
{
"type": "text",
"text": "Introduction"
}
]
},
{
"type": "heading",
"level": 2,
"content": [
{
"type": "text",
"text": "Structure"
}
]
},
{
"type": "paragraph",
"content": [
{
"type": "text",
"text": "Alinea generates files on your file system in two places. First content will be placed in a directory as `json` files. Second a library is generated inside the `.alinea` folder which allows us to interact with the content in JavaScript."
}
]
},
{
"id": "28hnf59Rd5Gbite3NVvsvobRTZz",
"type": "CodeBlock",
"code": "// Published content is stored in json files \n// inside the content directory\ncontent\n├ data // data root\n│ ├ index.json\n│ ├ blog.json\n│ ╰ blog\n│ ├ blog-post.json\n│ ╰ another-blog-post.json\n╰ media // media root\n ├ image.png.json\n ╰ file.pdf.json\n\n// The alinea directory exports a javascript library\n// per workspace\n.alinea\n╰ web",
"compact": true
},
{
"type": "heading",
"level": 2,
"content": [
{
"type": "text",
"text": "The .alinea package"
}
]
},
{
"type": "paragraph",
"content": [
{
"type": "text",
"text": "For each workspace a few exports can be found under `.alinea/$workspace`. In the example above we can query pages of the web workspace by importing its `Pages` instance."
}
]
},
{
"id": "28hwTlSifcft8pjRXYWoRGYMMMA",
"type": "CodeBlock",
"code": "import {pages} from '.alinea/web/pages'\n\nconst blog = await pages.findFirst(page => page.type.is('BlogOverview'))\nconst posts = await blog.tree.children()"
},
{
"type": "heading",
"level": 3,
"content": [
{
"type": "text",
"text": "Collections"
}
]
},
{
"type": "paragraph",
"content": [
{
"type": "text",
"text": "For each type defined in the workspace schema a `Collection` is exported. Collections are used to point at specific fields when querying."
}
]
},
{
"id": "28i0o6Hkw7J6px87T32tPA5vUNB",
"type": "CodeBlock",
"code": "import {pages} from '.alinea/web/pages'\nimport {Animal, Fruit} from '.alinea/web'\n\nconst page = await pages.findFirst(\n Animal.age.greater(10)\n)\nconst pages = await pages.findMany(\n Fruit.title.isIn(['apple', 'orange'])\n)"
}
]
}
]
}
213 changes: 213 additions & 0 deletions apps/web/content/data/docs/content/pages.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@
{
"id": "28hxVNf3JO9raYJ1HVQ6XgDX9pW",
"type": "Doc",
"root": "data",
"index": "a1",
"title": "Pages",
"parents": [
"docs",
"28Ng5RzmZ2fHUVlVbAEv1l1oUUS"
],
"blocks": [
{
"id": "28hxdvUqGndCClRgqppvMox36da",
"index": "a0",
"type": "TextBlock",
"text": [
{
"type": "heading",
"level": 1,
"content": [
{
"type": "text",
"text": "Pages"
}
]
},
{
"type": "paragraph",
"content": [
{
"type": "text",
"text": "A pages instance is used to query the data stored in the cms."
}
]
},
{
"type": "heading",
"level": 2,
"content": [
{
"type": "text",
"text": "Retrieving a page"
}
]
},
{
"type": "paragraph",
"content": [
{
"type": "text",
"text": "A single page can be fetched using the `findFirst` method. Criteria can be passed to filter entries."
}
]
},
{
"id": "28hy8mAMZJiFhtaajix2fKGBKBE",
"type": "CodeBlock",
"code": "// Fetch the first page where field equals the string 'value'\nconst page: AnyPage | undefined = await pages\n .findFirst(page => page.field.is('value'))"
},
{
"type": "heading",
"level": 2,
"content": [
{
"type": "text",
"text": "Retrieving multiple pages"
}
]
},
{
"type": "paragraph",
"content": [
{
"type": "text",
"text": "Multiple pages can be fetched using the `findMany` method."
}
]
},
{
"id": "28hyQUttn286uRfAArTKdMWNJVb",
"type": "CodeBlock",
"code": "// Fetch all pages where field equals the string 'value'\nconst pages: Array<AnyPage> = await pages\n .findMany(page => page.field.is('value'))"
},
{
"type": "heading",
"level": 3,
"content": [
{
"type": "text",
"text": "Limiting results"
}
]
},
{
"type": "paragraph",
"content": [
{
"type": "text",
"text": "A result set can be limited using `skip` and `take`."
}
]
},
{
"id": "28hyZtRcyC7fXKRHUiqhjA5O7iA",
"type": "CodeBlock",
"code": "// Skip the first 10 pages and return a maximum of 10\nconst limited = await pages\n .all()\n .skip(10)\n .take(10)"
},
{
"type": "heading",
"level": 3,
"content": [
{
"type": "text",
"text": "Ordering results"
}
]
},
{
"type": "paragraph",
"content": [
{
"type": "text",
"text": "A result set can be ordered by passing one or multiple fields."
}
]
},
{
"id": "28hzjFJi5kuByP0j3ZX79ATIyyS",
"type": "CodeBlock",
"code": "const ordered = await pages\n .all()\n .orderBy(Type.foo.asc(), Type.bar.desc())"
},
{
"type": "heading",
"level": 2,
"content": [
{
"type": "text",
"text": "Group by"
}
]
},
{
"type": "paragraph",
"content": [
{
"type": "text",
"text": "Results can be grouped by one or more fields."
}
]
},
{
"id": "28i0B7nRFUqmGWdCmchhzy21bkt",
"type": "CodeBlock",
"code": "const grouped = await pages\n .all()\n .groupBy(Type.foo, Type.bar)"
},
{
"type": "heading",
"level": 2,
"content": [
{
"type": "text",
"text": "Selecting specific fields"
}
]
},
{
"type": "paragraph",
"content": [
{
"type": "text",
"text": "Resulting rows can be narrowed to contain only specific fields."
}
]
},
{
"id": "28hywuwvVMmRT7zhyZEumjM19tI",
"type": "CodeBlock",
"code": "// Return only titles\nconst rows = await pages\n .all()\n .select(page => ({\n title: page.title\n })"
},
{
"type": "heading",
"level": 2,
"content": [
{
"type": "text",
"text": "Processing fields"
}
]
},
{
"type": "paragraph",
"content": [
{
"type": "text",
"text": "It's possible to process field values by passing a function, which can be `async`."
}
]
},
{
"id": "28hzx0owdbqFdAaJg0H31HP9OpI",
"type": "CodeBlock",
"code": "const row = await pages\n .findFirst()\n .select(page => ({\n title: \n page.title.process(title => `process title ${title}`)\n })"
}
]
},
{
"id": "28hxVjJYEVPAinTI27Fzx2OHRWK",
"index": "a1",
"type": "TypesBlock",
"types": "PageTree"
}
]
}
Loading

0 comments on commit 9c9ffbe

Please sign in to comment.