@@ -2,6 +2,10 @@ const showdown = require('showdown')
2
2
var toCss = require ( 'to-css' )
3
3
const CleanCSS = require ( 'clean-css' )
4
4
const createHTML = require ( 'create-html' )
5
+ const corner = require ( '../utils/githubCorner' )
6
+ const capitalize = require ( '../utils/capitalize' )
7
+ const fiddlyImports = require ( '../utils/fiddlyImports.js' )
8
+ const header = require ( '../utils/header.js' )
5
9
6
10
showdown . extension ( 'header-anchors' , function ( ) {
7
11
var ancTpl =
@@ -30,25 +34,16 @@ module.exports = {
30
34
name : 'fiddly' ,
31
35
run : async toolbox => {
32
36
const {
33
- parameters,
34
- template : { generate } ,
35
37
print : { info, success } ,
36
38
filesystem
37
39
} = toolbox
38
40
const options =
39
41
filesystem . read ( `${ process . cwd ( ) } /.fiddly.config.json` , 'json' ) || { }
40
42
const dist = options . dist || 'public'
43
+ const packageJSON =
44
+ filesystem . read ( `${ process . cwd ( ) } /package.json` , 'json' ) || { }
41
45
42
46
// CSS
43
-
44
- const styleString = style =>
45
- Object . entries ( style ) . reduce ( ( styleString , [ propName , propValue ] ) => {
46
- propName = propName . replace (
47
- / ( [ A - Z ] ) / g,
48
- matches => `-${ matches [ 0 ] . toLowerCase ( ) } `
49
- )
50
- return `${ styleString } ${ propName } :${ propValue } ;`
51
- } , '' )
52
47
const css = filesystem . read ( `${ __dirname } /css/css.css` ) . concat (
53
48
toCss ( options . styles , {
54
49
selector : s => `#fiddly ${ s } ` ,
@@ -62,38 +57,25 @@ module.exports = {
62
57
)
63
58
64
59
// HTML
65
- const name = options . file || 'Readme' || 'readme' || 'README'
66
- const markdown = filesystem . read ( `${ process . cwd ( ) } /${ name } .md` )
67
-
68
- const header =
69
- options && ! options . noHeader
70
- ? `<header>${ options . name ? `<h1>${ options . name } </h1>` : '' } ${
71
- options . logo
72
- ? `<img class="logo" src="${ options . logo } " alt="logo" />`
73
- : ''
74
- } </header>`
75
- : ''
60
+ const file = options . file || 'Readme' || 'readme' || 'README'
61
+ const markdown = filesystem . read ( `${ process . cwd ( ) } /${ file } .md` )
62
+ const description = options . description || packageJSON . description
63
+ const name = options . name || packageJSON . name
76
64
77
65
var html = createHTML ( {
78
- title : options . name ,
79
- css : [
80
- 'https://rawcdn.githack.com/yegor256/tacit/42137b0c4369dbc6616aef1b286cda5aff467314/tacit-css-1.3.5.min.css' ,
81
- 'style.css' ,
82
- 'https://unpkg.com/[email protected] /themes/prism.css'
83
- ] ,
66
+ title : capitalize ( name ) ,
67
+ css : fiddlyImports . css ,
84
68
scriptAsync : true ,
85
- script : [
86
- 'https://unpkg.com/[email protected] /prism.js' ,
87
- 'https://unpkg.com/[email protected] /components/prism-json.min.js' ,
88
- 'https://unpkg.com/[email protected] /components/prism-bash.min.js'
89
- ] ,
69
+ script : fiddlyImports . js ,
90
70
lang : 'en' ,
91
- head : `<meta charset="utf-8" /><meta http-equiv="x-ua-compatible" content="ie=edge" /><meta name="description" content="${
92
- options . description
93
- } " /><meta name="viewport" content="width=device-width, initial-scale=1" />`,
71
+ head : `<meta charset="utf-8" /><meta http-equiv="x-ua-compatible" content="ie=edge" /><meta name="description" content="${ description } " /><meta name="viewport" content="width=device-width, initial-scale=1" />` ,
94
72
body : `<div id="fiddly"><div class="body ${
95
73
options . darkTheme ? 'dark' : ''
96
- } "><div class="container">${ header } ${ converter . makeHtml (
74
+ } "><div class="container">${
75
+ packageJSON . repository
76
+ ? corner ( packageJSON . repository . url , options . darkTheme )
77
+ : ''
78
+ } ${ header ( options , name ) } ${ converter . makeHtml (
97
79
markdown
98
80
) } </div></div></div>`,
99
81
favicon : options . favicon || null
0 commit comments