Skip to content

Commit

Permalink
feat: added file plugin and runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
d3m1d0v committed Nov 13, 2024
1 parent 0cc22ed commit 90f95ba
Show file tree
Hide file tree
Showing 14 changed files with 1,364 additions and 16 deletions.
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,35 @@

[![NPM version](https://img.shields.io/npm/v/@diplodoc/file-extension.svg?style=flat)](https://www.npmjs.org/package/@diplodoc/file-extension)

```md
{% file src="path/to/file" name='readme.md' %}

==>

<a href="path/to/file" download="readme.md" class="yfm-file"><span class="yfm-file__icon"></span>readme.md</a>
```

## Attributes

| Name | Required | Description |
| ---------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------- |
| `src` | yes | URL of the file. Will be mapped to [`href` attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#attr-href) |
| `name` | yes | Name of the file. Will be mapped to [`download` attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#attr-download) |
| `lang` | - | Language of the file content. Will be mapped to [`hreflang` attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#attr-hreflang) |
| `referrerpolicy` | - | [`referrerpolicy` attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#attr-referrerpolicy) |
| `rel` | - | [`rel` attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#attr-rel) |
| `target` | - | [`target` attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#attr-target) |
| `type` | - | [`type` attribute](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/a#attr-type) |

> _Note: other attributes will be ignored_
## Options

| Name | Type | Description |
| ---------------- | -------------------- | ------------------------------------------------ |
| `fileExtraAttrs` | `[string, string][]` | Adds additional attributes to rendered hyperlink |

## CSS public variables

- `--yfm-file-icon` – sets custom file icon image
- `--yfm-file-icon-color` – sets custom file icon color
34 changes: 30 additions & 4 deletions esbuild/build.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env node

import {build} from 'esbuild';
import {sassPlugin} from 'esbuild-sass-plugin';

import tsConfig from '../tsconfig.json' assert {type: 'json'};

Expand All @@ -14,9 +15,34 @@ const common = {
tsconfig: './tsconfig.publish.json',
};

build({
/** @type {import('esbuild').BuildOptions}*/
const plugin = {
...common,
entryPoints: ['src/index.ts'],
outfile: outDir + '/index.js',
entryPoints: ['src/plugin/index.ts'],
outfile: outDir + '/plugin/index.js',
platform: 'node',
packages: 'external',
});
};

/** @type {import('esbuild').BuildOptions}*/
const pluginNode = {
...common,
entryPoints: ['src/plugin/index-node.ts'],
outfile: outDir + '/plugin/index-node.js',
platform: 'node',
packages: 'external',
};

/** @type {import('esbuild').BuildOptions}*/
const runtime = {
...common,
entryPoints: ['src/runtime/index.ts'],
outfile: outDir + '/runtime/index.js',
minify: true,
platform: 'browser',
plugins: [sassPlugin()],
};

build(plugin);
build(pluginNode);
build(runtime);
Loading

0 comments on commit 90f95ba

Please sign in to comment.