Skip to content

Commit

Permalink
fix: Clean up files in repo (#2963)
Browse files Browse the repository at this point in the history
BREAKING CHANGE:

- remove built files from git repo.
  - If you need to use the latest version of marked on the web you can use a cdn to get marked.min.js from npm:
  - `https://cdn.jsdelivr.net/npm/marked/marked.min.js`
  • Loading branch information
UziTech committed Sep 9, 2023
1 parent ccc7a8f commit 7d95a91
Show file tree
Hide file tree
Showing 21 changed files with 459 additions and 8,176 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,8 @@
node_modules/
test/compiled_tests
public
lib
docs/LICENSE.md
vuln.js
man/marked.1
marked.min.js
15 changes: 0 additions & 15 deletions Makefile

This file was deleted.

10 changes: 0 additions & 10 deletions component.json

This file was deleted.

22 changes: 16 additions & 6 deletions build-docs.js → docs/build.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* global marked */
import '../marked.min.js';
import { promises } from 'fs';
import { join, dirname, parse, format } from 'path';
import { Marked } from './lib/marked.esm.js';
import { markedHighlight } from 'marked-highlight';
import { HighlightJS } from 'highlight.js';
import titleize from 'titleize';
Expand All @@ -13,7 +14,7 @@ const outputDir = join(cwd, 'public');
const templateFile = join(inputDir, '_document.html');
const isUppercase = str => /[A-Z_]+/.test(str);
const getTitle = str => str === 'INDEX' ? '' : titleize(str.replace(/_/g, ' ')) + ' - ';
const marked = new Marked(markedHighlight((code, language) => {
const markedInstance = new marked.Marked(markedHighlight((code, language) => {
if (!language) {
return highlightAuto(code).value;
}
Expand All @@ -24,28 +25,38 @@ async function init() {
console.log('Cleaning up output directory ' + outputDir);
await rm(outputDir, { force: true, recursive: true });
await mkdir(outputDir);
console.log(`Copying file ${join(inputDir, 'LICENSE.md')}`);
await copyFile(join(cwd, 'LICENSE.md'), join(inputDir, 'LICENSE.md'));
console.log(`Copying file ${join(outputDir, 'marked.min.js')}`);
await copyFile(join(cwd, 'marked.min.js'), join(outputDir, 'marked.min.js'));
const tmpl = await readFile(templateFile, 'utf8');
console.log('Building markdown...');
await build(inputDir, tmpl);
console.log('Build complete!');
}

const ignoredFiles = [
join(cwd, 'docs', 'build.js'),
join(cwd, 'docs', '.eslintrc.json'),
join(cwd, 'docs', '_document.html')
];

async function build(currentDir, tmpl) {
const files = await readdir(currentDir);
for (const file of files) {
const filename = join(currentDir, file);
if (ignoredFiles.includes(filename)) {
continue;
}
const stats = await stat(filename);
const { mode } = stats;
if (stats.isDirectory()) {
// console.log('Found directory ' + filename);
await build(filename, tmpl);
} else {
// console.log('Reading file ' + filename);
let html = await readFile(filename, 'utf8');
const parsed = parse(filename);
if (parsed.ext === '.md' && isUppercase(parsed.name)) {
const mdHtml = marked.parse(html);
const mdHtml = markedInstance.parse(html);
html = tmpl
.replace('<!--{{title}}-->', getTitle(parsed.name))
.replace('<!--{{content}}-->', mdHtml);
Expand All @@ -55,7 +66,6 @@ async function build(currentDir, tmpl) {
}
parsed.dir = parsed.dir.replace(inputDir, outputDir);
const outfile = format(parsed);
// console.log('Ensure directory ' + dirname(outfile));
await mkdir(dirname(outfile), { recursive: true });
console.log('Writing file ' + outfile);
await writeFile(outfile, html, { mode });
Expand Down
1 change: 1 addition & 0 deletions docs/demo/demo.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ html, body {
color: #333;
background-color: #fbfbfb;
height: 100%;
overflow: auto;
}

textarea {
Expand Down

1 comment on commit 7d95a91

@vercel
Copy link

@vercel vercel bot commented on 7d95a91 Sep 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.