Skip to content

Commit

Permalink
fix: better typings exports
Browse files Browse the repository at this point in the history
  • Loading branch information
JulianCataldo committed Feb 8, 2024
1 parent f0fe42e commit 61f3f0c
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 26 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
[![Prettier](https://img.shields.io/badge/Prettier-333333?logo=prettier)](https://prettier.io)
[![EditorConfig](https://img.shields.io/badge/EditorConfig-333333?logo=editorconfig)](https://editorconfig.org)

Generate OG images from a static folder. Extract metadata from HTML pages. No headless browser involved.
Generate OG images from a static folder and / or a middleware.
Extract metadata from HTML pages. No headless browser involved.
Comes as a CLI, API or plugins.

---
Expand Down Expand Up @@ -40,7 +41,7 @@ npm i og-images-generator

Create a `og-images.config.js` in your current workspace root.

See [demos/vanilla/og-images.config.js](./demos/vanilla/og-images.config.js) for a full working example.
See this [og-images.example-config.js](./demos/__common/og-images.example-config.js) for a full working example. It's the config used in every [demo](./demos/).

The gist is:

Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "og-images-generator",
"version": "0.0.2",
"description": "Generate OG images from a static folder. Extract metadata from HTML pages. No headless browser involved.",
"version": "0.0.3",
"description": "Generate OG images from a static folder and / or a middleware.\nExtract metadata from HTML pages. No headless browser involved.\nComes as a CLI, API or plugins.",
"keywords": [
"og-images",
"social-networks",
Expand Down Expand Up @@ -60,7 +60,8 @@
"dev": "npm run dev:test & npm run dev:types",
"dev:types": "npm run types -- --watch",
"dev:test": "npm run test -- --watch",
"types": "tsc --project tsconfig.build.json",
"types": "npm run clean && npx tsc --project tsconfig.build.json",
"clean": "rm -rf ./types",
"test": "node --test",
"build:docs": "typedoc --tsconfig tsconfig.build.json --entryPoints src/index.js src/api.js",
"release": "npm run types && npm publish"
Expand Down
32 changes: 15 additions & 17 deletions src/collect.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,19 @@ import c from 'picocolors';

/**
* @typedef {Record<string, string>} MetaTags
*/
/**
* @typedef {Record<string, any>[]} JsonLds
*
* @typedef Metadata
* @property {MetaTags} tags
* @property {JsonLds} jsonLds
*
* @typedef Page
* @property {Metadata} meta
* @property {string} path
*/
/**
* @typedef Metadata
* @property {MetaTags} tags
* @property {Record<string, any>[]} jsonLds
*/

// NOTE: unexposed for now
// * @property {unknown} ast - Parse5 AST is untyped.

/**
* @typedef PathsOptions
* @property {string} [base]
* @property {string} [out]
* @property {string} [json]
*
* @typedef {Required<PathsOptions>} CollectOptions
*/

/**
* @param {string} fileContent
* @returns {Metadata}
Expand Down Expand Up @@ -92,6 +81,15 @@ export function extractMetadataFromHtml(fileContent) {
return { tags: metaTags, jsonLds };
}

/**
* @typedef PathsOptions
* @property {string} [base]
* @property {string} [out]
* @property {string} [json]
*
* @typedef {Required<PathsOptions>} CollectOptions
*/

/**
* @param {CollectOptions} options
* @returns {Promise<Page[]>}
Expand Down
7 changes: 3 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
* SPDX-License-Identifier: ISC
*/

// export * from './generate.js';

/** @typedef {import('./collect.js').MetaTags} Metadata */
/** @typedef {import('./collect.js').Metadata} Metadata */
/** @typedef {import('./collect.js').PathsOptions} PathsOptions */
/** @typedef {import('./collect.js').Page} Page */

export { fetchFont, OG_SIZE, FONTS } from './render.js';
/** @typedef {import('./render.js').RenderOptions} RenderOptions */
Expand All @@ -23,7 +22,7 @@ export const html = litHtml;
* @typedef {import('@lit-labs/ssr').ServerRenderedTemplate} LitServerTemplate
*
* @typedef TemplateOptions
* @property {import('./collect.js').Page} page
* @property {Page} page
*
* @typedef {(options: TemplateOptions) => LitServerTemplate} Template
*/

0 comments on commit 61f3f0c

Please sign in to comment.