Skip to content

Commit cccf2f5

Browse files
feat(theme): added themeing of svg output
1 parent 25f1a12 commit cccf2f5

File tree

201 files changed

+47972
-236
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

201 files changed

+47972
-236
lines changed

Diff for: README.md

+193-1
Large diffs are not rendered by default.

Diff for: build/head.md

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[![GitHub package version](https://img.shields.io/github/package-json/v/basics/code-snippet-to-svg.svg)](https://github.com/basics/code-snippet-to-svg)
2+
[![license](https://img.shields.io/github/license/basics/code-snippet-to-svg.svg)](https://github.com/basics/code-snippet-to-svg)
3+
4+
[![OSX/Linux Build Status](https://travis-ci.org/basics/code-snippet-to-svg.svg?branch=master)](https://travis-ci.org/basics/code-snippet-to-svg)
5+
[![Build status](https://ci.appveyor.com/api/projects/status/jrxx8092yxd8d07b?svg=true)](https://ci.appveyor.com/project/StephanGerbeth/code-snippet-to-svg)
6+
[![NSP Status](https://nodesecurity.io/orgs/basics/projects/d5bb0c4d-6232-4370-9886-571c516cd985/badge)](https://nodesecurity.io/orgs/basics/projects/d5bb0c4d-6232-4370-9886-571c516cd985)
7+
[![Dependencies Status](https://david-dm.org/basics/code-snippet-to-svg/status.svg)](https://david-dm.org/basics/code-snippet-to-svg)
8+
[![DevDependencies Status](https://david-dm.org/basics/code-snippet-to-svg/dev-status.svg)](https://david-dm.org/basics/code-snippet-to-svg?type=dev)
9+
10+
[![start with why](https://img.shields.io/badge/start%20with-why%3F-brightgreen.svg?style=flat)](http://www.ted.com/talks/simon_sinek_how_great_leaders_inspire_action)
11+
[![JavaScript Style Guide: Good Parts](https://img.shields.io/badge/code%20style-goodparts-brightgreen.svg?style=flat)](https://github.com/dwyl/goodparts "JavaScript The Good Parts") [![Greenkeeper badge](https://badges.greenkeeper.io/basics/code-snippet-to-svg.svg)](https://greenkeeper.io/)
12+
13+
# Code snippet to SVG converter

Diff for: build/readme.js

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
const glob = require('fast-glob');
2+
const fs = require('fs');
3+
4+
const url = 'basics/code-snippet-to-svg/blob/master/examples/example.js';
5+
6+
Promise.all([
7+
glob('*.itermcolors', {
8+
cwd: './schemes'
9+
}).then(entries => entries
10+
.map((entry) => {
11+
const name = entry.replace(/(\.[\w]+)$/, '');
12+
return `[![code preview](https://us-central1-code-snippet-to-svg.cloudfunctions.net/default/${url}?range=1-18&theme=${name})](https://github.com/${url}#L1L18)`;
13+
})
14+
.join('\n')),
15+
new Promise((resolve, reject) => {
16+
fs.readFile('./build/head.md', (err, data) => {
17+
if (err) {
18+
reject(err);
19+
}
20+
resolve(data.toString());
21+
});
22+
})
23+
]).then(([schemes, head]) => {
24+
console.log(head);
25+
fs.writeFileSync('README.md', `${head}\n${schemes}`);
26+
});

Diff for: functions/index.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,17 @@ function getMinMax(value = '1') {
1414
return value.split('-');
1515
}
1616

17-
function getCodeAsSVG(path, range = '1', lang = null) {
17+
function getCodeAsSVG(path, range = '1', lang, theme) {
1818
const url = githubRawUrl + path;
1919
return request({ uri: url }).then((code) => {
2020
const [min, max] = getMinMax(range);
21-
return codeToSVG(code, min, max, lang);
21+
return codeToSVG(code, min, max, lang, theme);
2222
});
2323
}
2424

2525
app.get(['/:account/:repo/*'], (req, res) => {
2626
const path = req.path.replace(/([\w-]*\/[\w-]*)(\/blob)/, '$1');
27-
getCodeAsSVG(path, req.query.range, req.query.lang).then((svg) => {
27+
getCodeAsSVG(path, req.query.range, req.query.lang, req.query.theme).then((svg) => {
2828
res.setHeader('Content-Type', 'image/svg+xml');
2929
res.send(Buffer.from(svg));
3030
});
@@ -34,7 +34,7 @@ exports.default = functions.https.onRequest(app);
3434

3535
exports.test = functions.https.onRequest((req, res) => {
3636
const path = '/GrabarzUndPartner/gp-vue-boilerplate/master/src/components/molecules/LinkList.vue';
37-
getCodeAsSVG(path, req.query.range, req.query.lang).then((svg) => {
37+
getCodeAsSVG(path, req.query.range, req.query.lang, req.query.theme).then((svg) => {
3838
res.setHeader('Content-Type', 'image/svg+xml');
3939
res.send(Buffer.from(svg));
4040
});

Diff for: functions/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"node": "8"
1313
},
1414
"dependencies": {
15-
"@js-basics/code-snippet-to-svg": "^1.2.0",
15+
"@js-basics/code-snippet-to-svg": "latest",
1616
"cors": "^2.8.4",
1717
"express": "^4.16.3",
1818
"firebase-admin": "~6.0.0",

0 commit comments

Comments
 (0)