# hypha

> transform a directory of content into JSON

Latest version **0.4.5** (published 2018-04-09) · MIT license · 0 weekly downloads

## Install

```sh
npm install hypha
pnpm add hypha
yarn add hypha
bun add hypha
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.4.5 |
| Published | 2018-04-09 |
| First published | 2017-12-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 10 |
| Unpacked size | 174.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 81 |
| Author | Jon-Kyle |
| Maintainers | jondashkyle |

## Links

- npm: https://www.npmjs.com/package/hypha
- Repository: https://github.com/jondashkyle/hypha
- Homepage: https://github.com/jondashkyle/hypha#readme
- Issues: https://github.com/jondashkyle/smarkt/issues
- npm.io page: https://npm.io/package/hypha

## Dependencies (10)

- [glob](https://npm.io/package/glob.md) ^7.1.2
- [pify](https://npm.io/package/pify.md) ^3.0.0
- [xtend](https://npm.io/package/xtend.md) ^4.0.1
- [smarkt](https://npm.io/package/smarkt.md) 0.0.6
- [js-yaml](https://npm.io/package/js-yaml.md) ^3.10.0
- [through2](https://npm.io/package/through2.md) ^2.0.3
- [object-keys](https://npm.io/package/object-keys.md) ^1.0.11
- [object-values](https://npm.io/package/object-values.md) ^1.0.0
- [static-module](https://npm.io/package/static-module.md) ^1.5.0
- [normalize-path](https://npm.io/package/normalize-path.md) ^2.1.1

## Recent versions

- 0.4.5 (latest) — 2018-04-09
- 0.4.4 — 2018-03-23
- 0.4.3 — 2018-03-12
- 0.4.2 — 2018-03-08
- 0.4.1 — 2018-03-06
- 0.4.0 — 2018-03-06
- 0.3.2 — 2018-02-17
- 0.3.1 — 2018-02-06
- 0.3.0 — 2018-02-02
- 0.2.0 — 2018-01-15
- 0.1.4 — 2018-01-05
- 0.1.3 — 2018-01-02
- 0.1.2 — 2018-01-02
- 0.1.1 — 2018-01-01
- 0.1.0 — 2017-12-27
- … 2 more at https://npm.io/package/hypha/versions

## README

<h1 align="center">⛺️ hypha</h1>

<div align="center"><b>UNDER CONSTRUCTION</b></div>

<div align="center">Transform folders and files into JSON</div>

## In a nutshell

- Store all of your content in a directory
- Each directory is a page
- The content for each page is stored in a text file
- Your file system becomes a router!

## Usage

Format some plain text files using [smarkt](https://github.com/jondashkyle/smarkt) fields.

```
title: Technopastoral
----
date: January 19, 2038
----
tags:
  - garden
  - engineering
----
text: To deprogram oneself necessitates keeping to very specific schedules, which are what Foucault, once again, described as techniques of the self, echoing Seneca. 
```

Organize them within a directory structure alongside media assets.

```
/content
  /about
    index.txt
  /blog
    /38-01-19-technopastoral
      index.txt
      header.jpg
  index.txt
```

Turn the directory into an object.

```js
var hypha = require('hypha')
var site = hypha.readSiteSync('./content')
```

Each directory becomes a path containing a sub-object of the content in your text file. 

```
{
  '/': { },
  '/about': { },
  '/blog': { },
  '/blog/30-01-19-technopastoral': { }
}
```

Map over the object keys to add routes to a router, then pass the content object. Huzzah.

## API

#### `.readFile(path, [options])`

#### `.readFiles(files, pathSite, [options])`

#### `.readPage(path, [options])`

#### `.readSite(path, [options])`

#### `.readFileSync(path, [options])`

#### `.readFilesSync(files, pathSite, [options])`

#### `.readPageSync(path, [options])`

#### `.readSiteSync(path, [options])`

## Options

#### `fs`

Provide a custom implementation of `fs`. Ensure the `mkdir` `readdir` `writeFile` and `readFile` methods are available. This is useful for replacing Node’s `fs` with Dat’s API, for instance.

#### `parse`

Substitute `smarkt` with your own parser. Must be able to transform a plain text file into a JSON object.

#### `parent`

Remove part of the `url` for pretty printing. For example, if your content lives in `/content`, but you don’t want to prefix all of your `urls` with `/content`, use `parent` to clean it up. Value can be a string or boolean. If `true`, the `path` of your initial call is used.

## Transform

```
browserify -t hypha/transform
```

A browserify transform located at `hypha/transform` is included to staticly inline the module output.

## Example

A demo site is included. Open the `hypha/example` dir and `npm install`. The example uses [Bankai](https://github.com/choojs/bankai). Run `npm start` to spin up a Bankai server and mess around. Run `bankai build` to build a fully static site.

## Todo

- [ ] Tests
- [ ] Async callback/promise fallback
- [x] Modularize read function for JSON/Smarkt/Custom

---
_Source: https://npm.io/package/hypha · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
