38 Commits

Author SHA1 Message Date
jkunz e11d0920bb v2.2.3 2026-05-01 16:32:34 +00:00
jkunz eec36e2e45 fix(build): modernize project configuration and test setup for current toolchain compatibility 2026-05-01 16:32:34 +00:00
philkunz 8e692b994e 2.2.2 2025-01-24 02:06:17 +01:00
philkunz 0ba0a9abbb fix(package): Fix export path in package.json 2025-01-24 02:06:17 +01:00
philkunz 2828b2eaf0 2.2.1 2025-01-24 02:04:54 +01:00
philkunz 4d0c97f948 fix(documentation): Remove unnecessary markdown syntax from the README. 2025-01-24 02:04:54 +01:00
philkunz 9b31263a32 2.2.0 2025-01-24 02:03:57 +01:00
philkunz 967b103e01 feat(core): Initial release of smartfm module for handling frontmatter 2025-01-24 02:03:57 +01:00
philkunz 89a691240b 2.1.2 2025-01-24 02:03:47 +01:00
philkunz 461d81d353 fix(documentation): Updated readme.md to add comprehensive examples and advanced use cases. 2025-01-24 02:03:47 +01:00
philkunz 6f9ac1cb99 2.1.1 2025-01-24 02:03:07 +01:00
philkunz 4c6e1e9c47 fix(documentation): Improved and updated README with detailed usage instructions 2025-01-24 02:03:07 +01:00
philkunz a11b4ee7df 2.1.0 2025-01-23 14:35:07 +01:00
philkunz 29568c88c3 feat(ci): Introduce new CI workflows for Gitea and remove GitLab CI 2025-01-23 14:35:06 +01:00
philkunz 5bfcb95c94 update npmextra.json: githost 2024-04-01 21:35:06 +02:00
philkunz 246ed4d74b update npmextra.json: githost 2024-04-01 19:58:17 +02:00
philkunz aee65a5d9a update npmextra.json: githost 2024-03-30 21:47:15 +01:00
philkunz b83e88eefb switch to new org scheme 2023-07-11 00:41:43 +02:00
philkunz 1821a1bdfd switch to new org scheme 2023-07-10 02:55:58 +02:00
philkunz af10b4eee5 2.0.4 2019-09-04 15:45:18 +02:00
philkunz fdc9cb6784 fix(core): update 2019-09-04 15:45:18 +02:00
philkunz 8db0cac292 2.0.3 2019-09-04 14:19:43 +02:00
philkunz dad6119945 fix(core): update 2019-09-04 14:19:43 +02:00
philkunz 369cb0a58c 2.0.2 2019-09-04 14:13:43 +02:00
philkunz 67ef49ddce fix(core): update 2019-09-04 14:13:42 +02:00
philkunz d6cf698327 2.0.1 2018-08-27 23:17:42 +02:00
philkunz 4fe9acb0ec fix(dependencies): remove obsolete import of typings-global 2018-08-27 23:17:41 +02:00
philkunz f8f74e32b5 2.0.0 2018-08-27 02:01:19 +02:00
philkunz 471b52c78e BREAKING CHANGE(scope): switch to @pushrocks scope 2018-08-27 02:01:18 +02:00
philkunz 5db9964480 1.0.5 2017-05-27 23:24:17 +02:00
philkunz fb94ff3be6 update ci yml 2017-05-27 23:24:09 +02:00
philkunz 0af5016d43 1.0.4 2017-05-27 23:09:27 +02:00
philkunz e52ff07b07 add npmextra.json 2017-05-27 23:09:23 +02:00
philkunz b056ab998d 1.0.3 2017-05-27 23:02:54 +02:00
philkunz b5f0bdc8e8 update to latest standards 2017-05-27 23:02:51 +02:00
philkunz a5a69ef25e update ci 2017-03-11 22:34:28 +01:00
philkunz 92da6611c7 1.0.2 2016-11-14 13:33:23 +01:00
philkunz 9288ed3d2c improve Readme 2016-11-14 13:33:16 +01:00
25 changed files with 8702 additions and 310 deletions
+66
View File
@@ -0,0 +1,66 @@
name: Default (not tags)
on:
push:
tags-ignore:
- '**'
env:
IMAGE: code.foss.global/host.today/ht-docker-node:npmci
NPMCI_COMPUTED_REPOURL: https://${{gitea.repository_owner}}:${{secrets.GITEA_TOKEN}}@/${{gitea.repository}}.git
NPMCI_TOKEN_NPM: ${{secrets.NPMCI_TOKEN_NPM}}
NPMCI_TOKEN_NPM2: ${{secrets.NPMCI_TOKEN_NPM2}}
NPMCI_GIT_GITHUBTOKEN: ${{secrets.NPMCI_GIT_GITHUBTOKEN}}
NPMCI_URL_CLOUDLY: ${{secrets.NPMCI_URL_CLOUDLY}}
jobs:
security:
runs-on: ubuntu-latest
continue-on-error: true
container:
image: ${{ env.IMAGE }}
steps:
- uses: actions/checkout@v3
- name: Install pnpm and npmci
run: |
pnpm install -g pnpm
pnpm install -g @ship.zone/npmci
- name: Run npm prepare
run: npmci npm prepare
- name: Audit production dependencies
run: |
npmci command npm config set registry https://registry.npmjs.org
npmci command pnpm audit --audit-level=high --prod
continue-on-error: true
- name: Audit development dependencies
run: |
npmci command npm config set registry https://registry.npmjs.org
npmci command pnpm audit --audit-level=high --dev
continue-on-error: true
test:
if: ${{ always() }}
needs: security
runs-on: ubuntu-latest
container:
image: ${{ env.IMAGE }}
steps:
- uses: actions/checkout@v3
- name: Test stable
run: |
npmci node install stable
npmci npm install
npmci npm test
- name: Test build
run: |
npmci node install stable
npmci npm install
npmci npm build
+124
View File
@@ -0,0 +1,124 @@
name: Default (tags)
on:
push:
tags:
- '*'
env:
IMAGE: code.foss.global/host.today/ht-docker-node:npmci
NPMCI_COMPUTED_REPOURL: https://${{gitea.repository_owner}}:${{secrets.GITEA_TOKEN}}@/${{gitea.repository}}.git
NPMCI_TOKEN_NPM: ${{secrets.NPMCI_TOKEN_NPM}}
NPMCI_TOKEN_NPM2: ${{secrets.NPMCI_TOKEN_NPM2}}
NPMCI_GIT_GITHUBTOKEN: ${{secrets.NPMCI_GIT_GITHUBTOKEN}}
NPMCI_URL_CLOUDLY: ${{secrets.NPMCI_URL_CLOUDLY}}
jobs:
security:
runs-on: ubuntu-latest
continue-on-error: true
container:
image: ${{ env.IMAGE }}
steps:
- uses: actions/checkout@v3
- name: Prepare
run: |
pnpm install -g pnpm
pnpm install -g @ship.zone/npmci
npmci npm prepare
- name: Audit production dependencies
run: |
npmci command npm config set registry https://registry.npmjs.org
npmci command pnpm audit --audit-level=high --prod
continue-on-error: true
- name: Audit development dependencies
run: |
npmci command npm config set registry https://registry.npmjs.org
npmci command pnpm audit --audit-level=high --dev
continue-on-error: true
test:
if: ${{ always() }}
needs: security
runs-on: ubuntu-latest
container:
image: ${{ env.IMAGE }}
steps:
- uses: actions/checkout@v3
- name: Prepare
run: |
pnpm install -g pnpm
pnpm install -g @ship.zone/npmci
npmci npm prepare
- name: Test stable
run: |
npmci node install stable
npmci npm install
npmci npm test
- name: Test build
run: |
npmci node install stable
npmci npm install
npmci npm build
release:
needs: test
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
container:
image: ${{ env.IMAGE }}
steps:
- uses: actions/checkout@v3
- name: Prepare
run: |
pnpm install -g pnpm
pnpm install -g @ship.zone/npmci
npmci npm prepare
- name: Release
run: |
npmci node install stable
npmci npm publish
metadata:
needs: test
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
runs-on: ubuntu-latest
container:
image: ${{ env.IMAGE }}
continue-on-error: true
steps:
- uses: actions/checkout@v3
- name: Prepare
run: |
pnpm install -g pnpm
pnpm install -g @ship.zone/npmci
npmci npm prepare
- name: Code quality
run: |
npmci command npm install -g typescript
npmci npm install
- name: Trigger
run: npmci trigger
- name: Build docs and upload artifacts
run: |
npmci node install stable
npmci npm install
pnpm install -g @git.zone/tsdoc
npmci command tsdoc
continue-on-error: true
+17 -2
View File
@@ -1,4 +1,19 @@
node_modules/
.nogit/
# artifacts
coverage/
public/
pages/
# installs
node_modules/
# caches
.yarn/
.cache/
.rpt2_cache
# builds
dist/
dist_*/
#------# custom
-59
View File
@@ -1,59 +0,0 @@
image: hosttoday/ht-docker-node:npmts
stages:
- test
- release
- trigger
- pages
testLEGACY:
stage: test
script:
- npmci test legacy
tags:
- docker
allow_failure: true
testLTS:
stage: test
script:
- npmci test lts
tags:
- docker
testSTABLE:
stage: test
script:
- npmci test stable
tags:
- docker
release:
stage: release
script:
- npmci publish
only:
- tags
tags:
- docker
trigger:
stage: trigger
script:
- npmci trigger
only:
- tags
tags:
- docker
pages:
image: hosttoday/ht-docker-node:npmpage
stage: pages
script:
- npmci command npmpage --host gitlab
only:
- tags
artifacts:
expire_in: 1 week
paths:
- public
+43
View File
@@ -0,0 +1,43 @@
{
"@git.zone/cli": {
"projectType": "npm",
"module": {
"githost": "code.foss.global",
"gitscope": "push.rocks",
"gitrepo": "smartfm",
"shortDescription": "frontmatter parser utilities",
"description": "A Node.js module for handling and processing frontmatter in markdown and text files, leveraging the gray-matter library for parsing and stringifying YAML or JSON formatted frontmatter.",
"npmPackagename": "@push.rocks/smartfm",
"license": "MIT",
"keywords": [
"frontmatter",
"markdown",
"text files",
"YAML",
"JSON",
"stringify",
"parse",
"commented sections",
"static site generator",
"CMS",
"content metadata",
"metadata management",
"gray-matter"
]
},
"release": {
"registries": [
"https://verdaccio.lossless.digital",
"https://registry.npmjs.org"
],
"accessLevel": "public"
}
},
"@git.zone/tsdoc": {
"legal": "\n## License and Legal Information\n\nThis repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository. \n\n**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.\n\n### Trademarks\n\nThis project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.\n\n### Company Information\n\nTask Venture Capital GmbH \nRegistered at District court Bremen HRB 35230 HB, Germany\n\nFor any legal inquiries or if you require further information, please contact us via email at hello@task.vc.\n\nBy using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.\n"
},
"@ship.zone/szci": {
"npmGlobalTools": [],
"npmRegistryUrl": "registry.npmjs.org"
}
}
+11
View File
@@ -0,0 +1,11 @@
{
"version": "0.2.0",
"configurations": [
{
"command": "npm test",
"name": "Run npm test",
"request": "launch",
"type": "node-terminal"
}
]
}
+26
View File
@@ -0,0 +1,26 @@
{
"json.schemas": [
{
"fileMatch": ["/npmextra.json"],
"schema": {
"type": "object",
"properties": {
"npmci": {
"type": "object",
"description": "settings for npmci"
},
"gitzone": {
"type": "object",
"description": "settings for gitzone",
"properties": {
"projectType": {
"type": "string",
"enum": ["website", "element", "service", "npm", "wcc"]
}
}
}
}
}
}
]
}
-68
View File
@@ -1,68 +0,0 @@
# smartfm
smartfm handles frontmatter of files
## Availabililty
[![npm](https://push.rocks/assets/repo-button-npm.svg)](https://www.npmjs.com/package/smartfm)
[![git](https://push.rocks/assets/repo-button-git.svg)](https://gitlab.com/pushrocks/smartfm)
[![git](https://push.rocks/assets/repo-button-mirror.svg)](https://github.com/pushrocks/smartfm)
[![docs](https://push.rocks/assets/repo-button-docs.svg)](https://pushrocks.gitlab.io/smartfm/)
## Status for master
[![build status](https://gitlab.com/pushrocks/smartfm/badges/master/build.svg)](https://gitlab.com/pushrocks/smartfm/commits/master)
[![coverage report](https://gitlab.com/pushrocks/smartfm/badges/master/coverage.svg)](https://gitlab.com/pushrocks/smartfm/commits/master)
[![Dependency Status](https://david-dm.org/pushrocks/smartfm.svg)](https://david-dm.org/pushrocks/smartfm)
[![bitHound Dependencies](https://www.bithound.io/github/pushrocks/smartfm/badges/dependencies.svg)](https://www.bithound.io/github/pushrocks/smartfm/master/dependencies/npm)
[![bitHound Code](https://www.bithound.io/github/pushrocks/smartfm/badges/code.svg)](https://www.bithound.io/github/pushrocks/smartfm)
[![TypeScript](https://img.shields.io/badge/TypeScript-2.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/)
[![node](https://img.shields.io/badge/node->=%206.x.x-blue.svg)](https://nodejs.org/dist/latest-v6.x/docs/api/)
[![JavaScript Style Guide](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/)
## Usage
say you have the following markdown file:
```markdown
---
title: A really awesome article
date: 23-10-2020
type: feature
---
# A Awesome Title
The world is cool. And here is why
* reason 1
* reason 2
```
```javascript
import * as smartfm from * smartfm
let markdownfile = `---
testKey: testValue
testKey2: testValue2
---
# some markdown`
// easy methods
let parsedData = smartfm.parse(markdownfile)
// parsedData will be object
/*
{
data: {
testKey: testValue,
testKey2: testValue2
},
content: '# some markdown',
orig: '---\ntestKey: testValue\ntestKey2: testValue2\n---\n# some markdown'
}
*/
let newFmString = smartfm.stringify('My awesome string', {testKey1: testValue1})
// newFmString will be '---\testKey1: testValue1\n---\nMyawesomeString'
# class Smartfm
let mySmartfm = new smartfm.Smartfm({
fmType: 'yaml' // can be yaml or json atm
})
```
[![npm](https://push.rocks/assets/repo-header.svg)](https://push.rocks)
+86
View File
@@ -0,0 +1,86 @@
# Changelog
## 2026-05-01 - 2.2.3 - fix(build)
modernize project configuration and test setup for current toolchain compatibility
- migrate npmextra metadata to scoped tool configuration and add .smartconfig.json
- update build, test, and formatting scripts alongside TypeScript compiler settings
- refresh development dependencies and gray-matter patch version
- rename the test entrypoint to test.node.ts and align imports with the new tstest tapbundle path
- add explicit return and parameter types to Smartfm methods to satisfy stricter TypeScript settings
## 2025-01-24 - 2.2.2 - fix(package)
Fix export path in package.json
- Corrected the export path from './dist/index.js' to './dist_ts/index.js' in package.json
## 2025-01-24 - 2.2.1 - fix(documentation)
Remove unnecessary markdown syntax from the README.
- Fixed minor formatting issue in the README file by removing extraneous markdown syntax.
## 2025-01-24 - 2.2.0 - feat(core)
Initial release of smartfm module for handling frontmatter
- Added Smartfm class to handle YAML and JSON frontmatter
- Implemented methods for parsing and stringifying frontmatter
- Included support for parseFromComments to handle commented out frontmatter
## 2025-01-24 - 2.1.2 - fix(documentation)
Updated readme.md to add comprehensive examples and advanced use cases.
- Added examples for initializing the Smartfm class with YAML and JSON frontmatter.
- Included detailed usage examples for parsing and stringifying frontmatter.
- Added complex scenarios and advanced use cases like using the module with static site generators and frontmatter validation.
## 2025-01-24 - 2.1.1 - fix(documentation)
Improved and updated README with detailed usage instructions
- Replaced placeholder text in README with complete usage guide
- Added comprehensive examples for parsing and stringifying frontmatter data
- Included detailed instructions on how to install and use the Smartfm class
## 2025-01-23 - 2.1.0 - feat(ci)
Introduce new CI workflows for Gitea and remove GitLab CI
- Added .gitea/workflows/default_nottags.yaml and .gitea/workflows/default_tags.yaml for Gitea CI workflow.
- Removed .gitlab-ci.yml indicating a shift from GitLab CI to Gitea CI.
- Updated package.json to use updated repository URLs conforming to the new hosting strategy.
- Updated README.md and npmextra.json with new npm package name and repository details.
## 2024-04-01 - 2.0.4 - Maintenance
Switch to a new organizational scheme and multiple updates to `npmextra.json`.
- Updated `npmextra.json` multiple times for consistency with `githost`.
- Switched to a new organization scheme.
## 2019-09-04 - 2.0.1 to 2.0.4 - Core Updates
Continual core updates to enhance stability.
- Core updates implemented in versions 2.0.1, 2.0.2, and 2.0.3.
## 2018-08-27 - 2.0.0 - Dependencies
Significant updates in dependencies management.
- Removed obsolete import of `typings-global`.
- Introduction of the 2.x series with dependency fixes.
## 2018-08-27 - 1.0.5 - BREAKING CHANGE
Transition to a new organizational scope.
- Switched to `@pushrocks` scope, marking a major change in project organization.
## 2017-05-27 - 1.0.3 - 1.0.4 - Configuration Updates
Enhancements in configuration and standards.
- Added `npmextra.json`.
- Updated CI YAML file.
- Adopted latest project standards.
## 2016-11-14 - 1.0.0 to 1.0.2 - Initial Release & Improvements
Initial project release with subsequent improvements.
- Initial working release.
- Improved Readme for better user guidance.
- Continuous updates to align with project standards.
-33
View File
@@ -1,33 +0,0 @@
import 'typings-global';
export declare type TFrontMatter = 'yaml' | 'json';
export interface IParsedFM {
data: any;
content: string;
orig: string;
}
export interface ISmartfmContructorOptions {
fmType: TFrontMatter;
}
/**
* class smartfm handles frontmatter
*/
export declare class Smartfm {
fmType: TFrontMatter;
constructor(optionsArg: ISmartfmContructorOptions);
/**
* add frontmatter to a string
*/
stringify(bodyString: string, frontmatterData: any): any;
/**
* parse a string that has frontmatter attached, YAML notation
*/
parse(stringToParse: string): IParsedFM;
}
/**
* parse a string that has frontmatter attached, YAML notation
*/
export declare let parse: (stringToParse: string) => IParsedFM;
/**
* add frontmatter to a string
*/
export declare let stringify: (bodyString: string, frontmatterData: any) => any;
-37
View File
@@ -1,37 +0,0 @@
"use strict";
require("typings-global");
let grayMatter = require('gray-matter');
/**
* class smartfm handles frontmatter
*/
class Smartfm {
constructor(optionsArg) {
this.fmType = optionsArg.fmType;
}
/**
* add frontmatter to a string
*/
stringify(bodyString, frontmatterData) {
return exports.stringify(bodyString, frontmatterData);
}
/**
* parse a string that has frontmatter attached, YAML notation
*/
parse(stringToParse) {
return exports.parse(stringToParse);
}
}
exports.Smartfm = Smartfm;
/**
* parse a string that has frontmatter attached, YAML notation
*/
exports.parse = (stringToParse) => {
return grayMatter(stringToParse);
};
/**
* add frontmatter to a string
*/
exports.stringify = (bodyString, frontmatterData) => {
return grayMatter.stringify(bodyString, frontmatterData);
};
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsMEJBQXVCO0FBQ3ZCLElBQUksVUFBVSxHQUFHLE9BQU8sQ0FBQyxhQUFhLENBQUMsQ0FBQTtBQWN2Qzs7R0FFRztBQUNIO0lBR0ksWUFBWSxVQUFxQztRQUM3QyxJQUFJLENBQUMsTUFBTSxHQUFHLFVBQVUsQ0FBQyxNQUFNLENBQUE7SUFDbkMsQ0FBQztJQUVEOztPQUVHO0lBQ0gsU0FBUyxDQUFDLFVBQWtCLEVBQUUsZUFBb0I7UUFDOUMsTUFBTSxDQUFDLGlCQUFTLENBQUMsVUFBVSxFQUFFLGVBQWUsQ0FBQyxDQUFBO0lBQ2pELENBQUM7SUFFRDs7T0FFRztJQUNILEtBQUssQ0FBQyxhQUFxQjtRQUN2QixNQUFNLENBQUMsYUFBSyxDQUFDLGFBQWEsQ0FBQyxDQUFBO0lBQy9CLENBQUM7Q0FDSjtBQXBCRCwwQkFvQkM7QUFFRDs7R0FFRztBQUNRLFFBQUEsS0FBSyxHQUFHLENBQUMsYUFBcUI7SUFDckMsTUFBTSxDQUFDLFVBQVUsQ0FBQyxhQUFhLENBQUMsQ0FBQTtBQUNwQyxDQUFDLENBQUE7QUFFRDs7R0FFRztBQUNRLFFBQUEsU0FBUyxHQUFHLENBQUMsVUFBa0IsRUFBRSxlQUFvQjtJQUM1RCxNQUFNLENBQUMsVUFBVSxDQUFDLFNBQVMsQ0FBQyxVQUFVLEVBQUUsZUFBZSxDQUFDLENBQUE7QUFDNUQsQ0FBQyxDQUFBIn0=
+19
View File
@@ -0,0 +1,19 @@
Copyright (c) 2026 Task Venture Capital GmbH <hello@task.vc>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
+43
View File
@@ -0,0 +1,43 @@
{
"@git.zone/cli": {
"projectType": "npm",
"module": {
"githost": "code.foss.global",
"gitscope": "push.rocks",
"gitrepo": "smartfm",
"shortDescription": "frontmatter parser utilities",
"description": "A Node.js module for handling and processing frontmatter in markdown and text files, leveraging the gray-matter library for parsing and stringifying YAML or JSON formatted frontmatter.",
"npmPackagename": "@push.rocks/smartfm",
"license": "MIT",
"keywords": [
"frontmatter",
"markdown",
"text files",
"YAML",
"JSON",
"stringify",
"parse",
"commented sections",
"static site generator",
"CMS",
"content metadata",
"metadata management",
"gray-matter"
]
},
"release": {
"registries": [
"https://verdaccio.lossless.digital",
"https://registry.npmjs.org"
],
"accessLevel": "public"
}
},
"@git.zone/tsdoc": {
"legal": "\n## License and Legal Information\n\nThis repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository. \n\n**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.\n\n### Trademarks\n\nThis project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.\n\n### Company Information\n\nTask Venture Capital GmbH \nRegistered at District court Bremen HRB 35230 HB, Germany\n\nFor any legal inquiries or if you require further information, please contact us via email at hello@task.vc.\n\nBy using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.\n"
},
"@ship.zone/szci": {
"npmGlobalTools": [],
"npmRegistryUrl": "registry.npmjs.org"
}
}
+49 -17
View File
@@ -1,32 +1,64 @@
{
"name": "smartfm",
"version": "1.0.1",
"description": "frontmatter done right",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"name": "@push.rocks/smartfm",
"version": "2.2.3",
"private": false,
"description": "A Node.js module for handling and processing frontmatter in markdown and text files, leveraging the gray-matter library for parsing and stringifying YAML or JSON formatted frontmatter.",
"exports": {
".": "./dist_ts/index.js"
},
"type": "module",
"scripts": {
"test": "(npmts)"
"test": "tstest test/",
"format": "gitzone format",
"build": "tsbuild tsfolders",
"buildDocs": "tsdoc"
},
"repository": {
"type": "git",
"url": "git+ssh://git@gitlab.com/pushrocks/smartfm.git"
"url": "git+https://code.foss.global/push.rocks/smartfm.git"
},
"keywords": [
"frontmatter"
"frontmatter",
"markdown",
"text files",
"YAML",
"JSON",
"stringify",
"parse",
"commented sections",
"static site generator",
"CMS",
"content metadata",
"metadata management",
"gray-matter"
],
"author": "Lossless GmbH",
"author": "Task Venture Capital GmbH <hello@task.vc>",
"license": "MIT",
"bugs": {
"url": "https://gitlab.com/pushrocks/smartfm/issues"
"url": "https://code.foss.global/push.rocks/smartfm/issues"
},
"homepage": "https://gitlab.com/pushrocks/smartfm#README",
"homepage": "https://code.foss.global/push.rocks/smartfm#readme",
"dependencies": {
"gray-matter": "^2.1.0",
"typings-global": "^1.0.14"
"gray-matter": "^4.0.3"
},
"devDependencies": {
"@types/should": "^8.1.30",
"should": "^11.1.1",
"typings-test": "^1.0.3"
}
"@git.zone/tsbuild": "^4.4.0",
"@git.zone/tsrun": "^2.0.3",
"@git.zone/tstest": "^3.6.3",
"@types/node": "^25.6.0"
},
"files": [
"ts/**/*",
"ts_web/**/*",
"dist/**/*",
"dist_*/**/*",
"dist_ts/**/*",
"dist_ts_web/**/*",
"assets/**/*",
"cli.js",
".smartconfig.json",
"license",
"npmextra.json",
"readme.md"
]
}
+7909
View File
File diff suppressed because it is too large Load Diff
+1
View File
@@ -0,0 +1 @@
+208
View File
@@ -0,0 +1,208 @@
# @push.rocks/smartfm
The `@push.rocks/smartfm` module handles frontmatter data in markdown and other text files. The module allows easy parsing, stringification, and extraction of frontmatter data, using YAML or JSON format. It leverages the `gray-matter` library for advanced functionality with a simple API.
## Install
To use `@push.rocks/smartfm`, you first need to install it via npm. Make sure you have Node.js installed, and run the following command in your terminal:
```sh
npm install @push.rocks/smartfm
```
This will add the module as a dependency to your project.
## Usage
Once the module is installed, you can start using its capabilities by importing and initializing the `Smartfm` class in your TypeScript or JavaScript projects. The following sections provide comprehensive examples of the module's functionality:
### Importing the Module
To get started with the module, use the following import statement:
```typescript
import { Smartfm } from '@push.rocks/smartfm';
```
The module exports the `Smartfm` class, which you will use to manipulate frontmatter in your files.
### Initializing the `Smartfm` Class
The `Smartfm` class requires an options object to be passed during initialization. The options object specifies the type of frontmatter format you are working with, which can either be `'yaml'` or `'json'`. Here's how you can initialize the class:
```typescript
// Initialize with YAML frontmatter
let smartfm = new Smartfm({ fmType: 'yaml' });
// Initialize with JSON frontmatter
let smartfmJSON = new Smartfm({ fmType: 'json' });
```
The initialized objects can then be used to parse and stringify frontmatter in strings and text files.
### Parsing Frontmatter from Strings
To parse frontmatter data from a string that includes frontmatter, use the `parse` method. This function returns an object containing the parsed frontmatter data and the rest of the string:
```typescript
const sampleString = `---
title: Test Document
author: John Doe
---
This is the body content of the file.`;
let parsedContent = smartfm.parse(sampleString);
console.log(parsedContent.data); // Outputs the frontmatter data as a JavaScript object
console.log(parsedContent.content); // Outputs "This is the body content of the file."
```
The `parse` method will recognize and extract the frontmatter block, returning it as a JavaScript object while preserving the original content of the string.
### Stringifying a String with Frontmatter
If you have a string and frontmatter data that you want to combine into a correctly formatted frontmatter block in a string, you can use the `stringify` method:
```typescript
const bodyContent = "This is some markdown content.";
const frontmatterData = {
date: "2023-01-01",
tags: ["example", "frontmatter"]
};
let combinedString = smartfm.stringify(bodyContent, frontmatterData);
console.log(combinedString);
// Outputs a string with the frontmatter serialized at the top
```
This method appends the serialized frontmatter to the top of the given body content, making it ready for use in typical markdown or frontmatter-supported documents.
### Parsing Frontmatter from Commented Sections
Sometimes frontmatter data might be commented out. The `parseFromComments` method allows you to parse such data by providing a comment prefix:
```typescript
const commentedFile = `# ---
# title: Commented Example
# date: 2023-10-15
# ---
Actual file content here...`;
let parsedCommentedContent = smartfm.parseFromComments('# ', commentedFile);
console.log(parsedCommentedContent.data); // Outputs { title: "Commented Example", date: "2023-10-15" }
```
The `parseFromComments` method strips the comment prefixes before parsing the frontmatter, enabling easy extraction of data listed in commented sections.
### Using the Module for Complex Scenarios
Beyond these basic operations, the `@push.rocks/smartfm` module can be a crucial part of more complex workflows. For instance, integrating frontmatter management with static site generators, content management systems (CMS), or any situation where content metadata is necessary.
#### Example Scenario: A Static Site Generator
Imagine a static site generator that uses markdown files with frontmatter as data sources for pages. `@push.rocks/smartfm` can help read, extract, and manipulate these files programmatically:
```typescript
import fs from 'fs';
import path from 'path';
const contentDir = path.join(process.cwd(), 'content');
fs.readdir(contentDir, (err, files) => {
if (err) throw err;
files.forEach(file => {
const filePath = path.join(contentDir, file);
fs.readFile(filePath, 'utf8', (err, data) => {
if (err) throw err;
const smartfmInstance = new Smartfm({ fmType: 'yaml' });
const parsedPage = smartfmInstance.parse(data);
console.log('Page Title:', parsedPage.data.title);
console.log('Markdown Content:', parsedPage.content);
// Optionally, modify and update frontmatter
parsedPage.data.title = 'Updated Title';
const updatedContent = smartfmInstance.stringify(parsedPage.content, parsedPage.data);
fs.writeFile(filePath, updatedContent, (err) => {
if (err) throw err;
console.log('File updated successfully.');
});
});
});
});
```
In this example, we read all markdown files from a directory, parse them to extract frontmatter data, optionally modify the frontmatter, and write the updated content back to the files.
### Advanced Use Cases
`@push.rocks/smartfm` is flexible enough to support advanced operations like validating frontmatter, applying transformations, and more. Here are a few ideas to explore:
#### Frontmatter Validation
You might want to validate the structure of frontmatter data against a schema before processing. Here's a conceptual idea using `@push.rocks/smartfm`:
```typescript
import Ajv from 'ajv';
const ajv = new Ajv();
const schema = {
type: 'object',
properties: {
title: { type: 'string' },
date: { type: 'string', format: 'date' }
},
required: ['title', 'date']
};
const validate = ajv.compile(schema);
const frontmatter = smartfm.parse(sampleString).data;
if (validate(frontmatter)) {
console.log('Frontmatter is valid.');
} else {
console.error('Frontmatter validation failed:', validate.errors);
}
```
Using a validation library like Ajv, you can ensure that the parsed frontmatter adheres to a required schema or format, enhancing data integrity in larger applications.
#### Transformed Output
Suppose you want to output the parsed markdown content in a transformed format, such as HTML. Heres how you could integrate a markdown parsing library:
```typescript
import marked from 'marked';
const parsedResult = smartfm.parse(sampleString);
const htmlContent = marked(parsedResult.content);
console.log('HTML Content:', htmlContent);
```
By combining `@push.rocks/smartfm` with a markdown parsing library like `marked`, you can convert markdown content into other formats while handling the associated frontmatter.
With these examples, you can see how `@push.rocks/smartfm` fits into various workflows involving frontmatter and text processing. The module's simplicity and effectiveness make it a suitable choice for projects that require clean handling of document metadata.
Feel free to explore and extend these examples based on your particular use case. Whether you are building a simple script, a web application, or an extensive content management system, `@push.rocks/smartfm` provides a robust foundation for frontmatter operations. Happy coding!
## License and Legal Information
This repository contains open-source code that is licensed under the MIT License. A copy of the MIT License can be found in the [license](license) file within this repository.
**Please note:** The MIT License does not grant permission to use the trade names, trademarks, service marks, or product names of the project, except as required for reasonable and customary use in describing the origin of the work and reproducing the content of the NOTICE file.
### Trademarks
This project is owned and maintained by Task Venture Capital GmbH. The names and logos associated with Task Venture Capital GmbH and any related products or services are trademarks of Task Venture Capital GmbH and are not included within the scope of the MIT license granted herein. Use of these trademarks must comply with Task Venture Capital GmbH's Trademark Guidelines, and any usage must be approved in writing by Task Venture Capital GmbH.
### Company Information
Task Venture Capital GmbH
Registered at District court Bremen HRB 35230 HB, Germany
For any legal inquiries or if you require further information, please contact us via email at hello@task.vc.
By using this repository, you acknowledge that you have read this section, agree to comply with its terms, and understand that the licensing of the code does not imply endorsement by Task Venture Capital GmbH of any derivative works.
-1
View File
@@ -1 +0,0 @@
import 'typings-test';
-25
View File
@@ -1,25 +0,0 @@
"use strict";
require("typings-test");
const should = require("should");
const smartfm = require("../dist/index");
describe('smartfm', function () {
let testSmartfm = new smartfm.Smartfm({ fmType: 'yaml' });
it('.parse()', function () {
let testString = `---
testKey: testValue
testKey2: testValue2
---
# some markdown`;
let parsedString = testSmartfm.parse(testString);
should(parsedString.data).have.property('testKey', 'testValue');
should(parsedString.data).have.property('testKey2', 'testValue2');
should(parsedString.orig).equal(testString);
});
it('.stringify', function () {
let testStringPure = `# some markdown heading\nsome first row`;
let testStringCombined = testSmartfm.stringify(testStringPure, { testData: 'hi' });
let resultString = '---\ntestData: hi\n---\n# some markdown heading\nsome first row\n';
should(resultString).equal(testStringCombined);
});
});
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLHdCQUFxQjtBQUNyQixpQ0FBZ0M7QUFFaEMseUNBQXdDO0FBRXhDLFFBQVEsQ0FBQyxTQUFTLEVBQUU7SUFDaEIsSUFBSSxXQUFXLEdBQUcsSUFBSSxPQUFPLENBQUMsT0FBTyxDQUFDLEVBQUUsTUFBTSxFQUFFLE1BQU0sRUFBRSxDQUFDLENBQUE7SUFDekQsRUFBRSxDQUFDLFVBQVUsRUFBRTtRQUNYLElBQUksVUFBVSxHQUFHOzs7O2dCQUlULENBQUE7UUFDUixJQUFJLFlBQVksR0FBRyxXQUFXLENBQUMsS0FBSyxDQUFDLFVBQVUsQ0FBQyxDQUFBO1FBQ2hELE1BQU0sQ0FBQyxZQUFZLENBQUMsSUFBSSxDQUFDLENBQUMsSUFBSSxDQUFDLFFBQVEsQ0FBQyxTQUFTLEVBQUUsV0FBVyxDQUFDLENBQUE7UUFDL0QsTUFBTSxDQUFDLFlBQVksQ0FBQyxJQUFJLENBQUMsQ0FBQyxJQUFJLENBQUMsUUFBUSxDQUFDLFVBQVUsRUFBRSxZQUFZLENBQUMsQ0FBQTtRQUNqRSxNQUFNLENBQUMsWUFBWSxDQUFDLElBQUksQ0FBQyxDQUFDLEtBQUssQ0FBQyxVQUFVLENBQUMsQ0FBQTtJQUMvQyxDQUFDLENBQUMsQ0FBQTtJQUNGLEVBQUUsQ0FBQyxZQUFZLEVBQUU7UUFDYixJQUFJLGNBQWMsR0FBRyx5Q0FBeUMsQ0FBQTtRQUM5RCxJQUFJLGtCQUFrQixHQUFHLFdBQVcsQ0FBQyxTQUFTLENBQUMsY0FBYyxFQUFFLEVBQUUsUUFBUSxFQUFFLElBQUksRUFBRSxDQUFDLENBQUE7UUFDbEYsSUFBSSxZQUFZLEdBQUcsbUVBQW1FLENBQUE7UUFDdEYsTUFBTSxDQUFDLFlBQVksQ0FBQyxDQUFDLEtBQUssQ0FBQyxrQkFBa0IsQ0FBQyxDQUFBO0lBQ2xELENBQUMsQ0FBQyxDQUFBO0FBQ04sQ0FBQyxDQUFDLENBQUEifQ==
+45
View File
@@ -0,0 +1,45 @@
import { tap, expect } from '@git.zone/tstest/tapbundle';
import * as smartfm from '../ts/index.js';
let testSmartfm = new smartfm.Smartfm({ fmType: 'yaml' });
tap.test('.parse()', async () => {
let testString = `---
testKey: testValue
testKey2: testValue2
---
# some markdown
`;
let parsedString = testSmartfm.parse(testString);
expect(parsedString.data).toHaveProperty('testKey', 'testValue');
expect(parsedString.data).toHaveProperty('testKey2', 'testValue2');
expect(parsedString.orig.toString()).toEqual(testString);
});
tap.test('should stringify data', async () => {
let testStringPure = `# some markdown heading\nsome first row`;
let testStringCombined = testSmartfm.stringify(testStringPure, { testData: 'hi' });
let resultString = '---\ntestData: hi\n---\n# some markdown heading\nsome first row\n';
expect(resultString).toEqual(testStringCombined);
});
tap.test('should parse a normal frontmatter file', async () => {
const normalFile = `---
heythere: awesome
---
really
`;
let result = testSmartfm.parse(normalFile);
expect(result.data.heythere).toEqual('awesome');
});
tap.test('should parse a commented out frontmatter file', async () => {
const commentedFile = `# ---
# heythere: awesome
# ---
really
`;
let result = testSmartfm.parseFromComments('# ', commentedFile);
console.log(result);
});
export default tap.start();
-25
View File
@@ -1,25 +0,0 @@
import 'typings-test'
import * as should from 'should'
import * as smartfm from '../dist/index'
describe('smartfm', function () {
let testSmartfm = new smartfm.Smartfm({ fmType: 'yaml' })
it('.parse()', function () {
let testString = `---
testKey: testValue
testKey2: testValue2
---
# some markdown`
let parsedString = testSmartfm.parse(testString)
should(parsedString.data).have.property('testKey', 'testValue')
should(parsedString.data).have.property('testKey2', 'testValue2')
should(parsedString.orig).equal(testString)
})
it('.stringify', function () {
let testStringPure = `# some markdown heading\nsome first row`
let testStringCombined = testSmartfm.stringify(testStringPure, { testData: 'hi' })
let resultString = '---\ntestData: hi\n---\n# some markdown heading\nsome first row\n'
should(resultString).equal(testStringCombined)
})
})
+8
View File
@@ -0,0 +1,8 @@
/**
* autocreated commitinfo by @push.rocks/commitinfo
*/
export const commitinfo = {
name: '@push.rocks/smartfm',
version: '2.2.3',
description: 'A Node.js module for handling and processing frontmatter in markdown and text files, leveraging the gray-matter library for parsing and stringifying YAML or JSON formatted frontmatter.'
}
+22 -30
View File
@@ -1,53 +1,45 @@
import 'typings-global'
let grayMatter = require('gray-matter')
import grayMatter from 'gray-matter';
export type TFrontMatter = 'yaml' | 'json'
export interface IParsedFM {
data: any
content: string
orig: string
}
export type TFrontMatter = 'yaml' | 'json';
export interface ISmartfmContructorOptions {
fmType: TFrontMatter
fmType: TFrontMatter;
}
/**
* class smartfm handles frontmatter
*/
export class Smartfm {
fmType: TFrontMatter
fmType: TFrontMatter;
constructor(optionsArg: ISmartfmContructorOptions) {
this.fmType = optionsArg.fmType
this.fmType = optionsArg.fmType;
}
/**
* add frontmatter to a string
*/
stringify(bodyString: string, frontmatterData: any) {
return stringify(bodyString, frontmatterData)
stringify(bodyString: string, frontmatterData: Record<string, unknown>): string {
return grayMatter.stringify(bodyString, frontmatterData);
}
/**
* parse a string that has frontmatter attached, YAML notation
*/
parse(stringToParse: string): IParsedFM {
return parse(stringToParse)
parse(stringToParse: string): grayMatter.GrayMatterFile<string> {
return grayMatter(stringToParse);
}
/**
* parse from comments
*/
parseFromComments(commentStart: string, stringToParse: string): grayMatter.GrayMatterFile<string> {
const diffFunc = (diffMe: string, diffBy: string): string => diffMe.split(diffBy).join('');
let lines = stringToParse.split('\n');
lines = lines.map((line) => {
return diffFunc(line, commentStart);
});
const cleanedString = lines.join('\n');
return this.parse(cleanedString);
}
}
/**
* parse a string that has frontmatter attached, YAML notation
*/
export let parse = (stringToParse: string): IParsedFM => {
return grayMatter(stringToParse)
}
/**
* add frontmatter to a string
*/
export let stringify = (bodyString: string, frontmatterData: any) => {
return grayMatter.stringify(bodyString, frontmatterData)
}
+15
View File
@@ -0,0 +1,15 @@
{
"compilerOptions": {
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"useDefineForClassFields": false,
"target": "ES2022",
"module": "NodeNext",
"moduleResolution": "NodeNext",
"noImplicitAny": true,
"esModuleInterop": true,
"verbatimModuleSyntax": true,
"types": ["node"]
},
"exclude": ["dist_*/**/*.d.ts"]
}
-3
View File
@@ -1,3 +0,0 @@
{
"extends": "tslint-config-standard"
}