Skip to content

Commit

Permalink
docs
Browse files Browse the repository at this point in the history
  • Loading branch information
ignatiusmb committed Mar 12, 2024
1 parent 00d1d7c commit 3e196ed
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 13 deletions.
6 changes: 3 additions & 3 deletions workspace/aubade/src/compass/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@ export function traverse(entry, { depth: level = 0 } = {}) {
*
* @template {object} Output
* @param {(chunk: import('../types.js').HydrateChunk) => undefined | Output} load
* @param {(path: string) => boolean} [filter] files to process with `load`
* @param {(path: string) => boolean} [files] filter item to process with `load`
* @returns {Output[]}
*/
hydrate(load, filter = (v) => v.endsWith('.md')) {
hydrate(load, files = (v) => v.endsWith('.md')) {
const items = [];
for (const { path, breadcrumb, buffer } of entries) {
if (!filter(path)) continue;
if (!files(path)) continue;
const item = load({
breadcrumb,
buffer,
Expand Down
45 changes: 35 additions & 10 deletions workspace/content/10-modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,26 +162,49 @@ export function visit<Output>(entry: string): Output & {

The first argument of `visit` is the source entry point.

### scan

```typescript
interface FileChunk {
type: 'file';
path: string;
breadcrumb: string[];
buffer: Buffer;
}

interface DirChunk {
type: 'directory';
path: string;
breadcrumb: string[];
buffer: undefined;
}

export function scan<T extends 'all' | 'files' | 'directories'>(
type: T,
entry: string,
): FileChunk[] | DirChunk[];
```

The first argument of `scan` is the type of item to scan, and the second argument is the entrypoint. It returns an array of `FileChunk` when `type` is `'files'`, `DirChunk` when `type` is `'directories'`, and both when `type` is `'all'`. The `entry` argument can be anything as long as it exists in the filesystem, though it would return an empty array if it's not a directory.

### traverse

```typescript
export function traverse(
entry: string,
options: {
options?: {
depth?: number;
files?(path: string): boolean;
},
): {
files: FileChunk[];
hydrate(
load: (chunk: HydrateChunk) => undefined | Output,
transform?: (items: Output[]) => Transformed,
): Transformed;
filter?: (path: string) => boolean,
): Output[];
};
```

The first argument of `traverse` is the directory entrypoint, and the second argument is its `options`. It returns an object with the `hydrate` method that accepts a `load` callback and an optional `transform` callback function.

The `files` property in `options` is an optional function that takes the full path of a file and returns a boolean. If the function returns `true`, the `load` callback will be called upon the file, else it will ignored and filtered out from the final output.
The first argument of `traverse` is the directory entrypoint, and the second argument is its `options`. It returns an object with the `hydrate` method that accepts a `load` callback and an optional `files` function to filter item to process into `load`, it takes the full path of a file and returns a boolean. If the function returns `true`, the `load` callback will be called upon the file, else it will ignored and filtered out from the final output.

```
content
Expand Down Expand Up @@ -247,13 +270,15 @@ const data = traverse('content/reviews', { depth: -1 }).hydrate(

## /transform

This module provides a set of transformer function for the [`traverse(...).hydrate(..., /* transform */)` parameter](/docs/modules#compass-traverse). These function can be used in conjunction with each other, by utilizing the `pipe` function provided from the `'mauss'` package and re-exported by this module, you can do the following
This is a standalone module which provides a set of transformer function. They can be used in conjunction with each other by utilizing the `pipe` function provided from the `'mauss'` package and re-exported by this module, you can do the following

```typescript
import { traverse } from 'aubade/compass';
import { pipe } from 'aubade/transform';
import { chain } from 'aubade/transform';

const items = traverse('path/to/content').hydrate(() => {});

traverse('path/to/content').hydrate(() => {}, pipe(/* ... */));
chain(items, { ... });
```

### chain
Expand Down

0 comments on commit 3e196ed

Please sign in to comment.