lintry

调整路由,增加默认readme.md的处理

......@@ -9,7 +9,7 @@ if (!target) {
process.exit(1);
}
const mdview = require('../lib/mdview')(),
const mdview = new (require('../lib/mdview')),
path = require('path');
const filename = path.resolve(process.cwd(), target);
......
"use strict";
const fs = require('fs');
function MarkdownIt(opts) {
if (!(this instanceof MarkdownIt)) {
return new MarkdownIt(opts);
}
function MarkdownIt (opts) {
if (!(this instanceof MarkdownIt)) {
return new MarkdownIt(opts);
}
opts = opts || {};
opts = opts || {};
var md = require('markdown-it')(opts.options);
const md = require('markdown-it')(opts.options);
this.renderFile = function(filename) {
if (!filename) {
throw new Error('filename can not be null!')
}
this.renderFile = function (filename) {
if (!filename) {
throw new Error('filename can not be null!')
}
try{
var content = fs.readFileSync(filename).toString();
var result = md.render(content);
} catch(e) {
result = md.render(`
## 404
let result;
try {
const content = fs.readFileSync(filename).toString();
result = md.render(content);
} catch (e) {
result = md.render(`
# 404
*文件找不到!*
`)
}
}
return result;
}
return result;
}
}
module.exports = MarkdownIt;
......

1010 KB

# 标题:如何编写帮助文档(H1)
> 每个描述目标简历一个子目录,在子目录下建立readme.md编写当前文档,本文档内需要的图片也存放在此目录下。
## 章节:文章的主要结构(H2)
### 小节:针对每个章节的具体描述(H3)
#### 段落:小节内需要分层次描述时使用(H4)
##### 节点:段落内需要重点提出时(H5)
正文:每个文件用一个H1作为标题,后续章节可以用到H2-H5
可以使用截图描述操作界面
![图片](alg.png)
对于需要特殊指出的词语可以使用`反引号`
**或者使用粗体重点提醒**
> *在引用内可以使用斜体*
也可用列表描述
- 使用无序列表
- 使用有序列表
通常很少会用到表格
| 标题1 | 标题2 | 标题3 |
| ---- | ---- | ---- |
| 内容1 | | |
| | 内容2 | |
| | | 内容3 |
中间可以用到分割线(HR)
----
分割线的上下有足够的空间
......@@ -16,7 +16,7 @@ dog's back.
### Header 3
> This is a blockquote.
>
>
> This is the second paragraph in the blockquote.
>
> ## This is an H2 in a blockquote
......@@ -41,7 +41,12 @@ Some of these words <em>are emphasized also</em>.</p>
Or, if you prefer, <strong>use two underscores instead</strong>.</p>
```
----
### LISTS
Unordered (bulleted) lists use asterisks, pluses, and hyphens (*, +, and -) as list markers. These three markers are interchangable; this:
* Candy.
......
......@@ -14,8 +14,8 @@
"author": "lintry <shenlin00@gmail.com>",
"license": "MIT",
"dependencies": {
"express": "^4.14.0",
"github-markdown-css": "^2.4.1",
"markdown-it": "^8.0.1"
"express": "^4.16.2",
"github-markdown-css": "^2.10.0",
"markdown-it": "^8.4.0"
}
}
......
var express = require('express')
var app = express()
const express = require('express');
const app = express();
const mdview = require('./lib/mdview')(),
path = require('path');
const mdview = new (require('./lib/mdview')),
path = require('path');
const MARKDOWN_FILE_BASE = process.cwd();
const MARKDOWN_FILE_BASE = path.resolve(process.cwd(), 'md');
app.use(express.static(__dirname + '/themes'));
app.use(express.static(MARKDOWN_FILE_BASE));
function sendTemplate(filename, theme) {
let file = path.resolve(MARKDOWN_FILE_BASE, filename);
var result = mdview.renderFile(file);
theme = theme || 'github-markdown';
return `
function sendTemplate (filename, theme) {
//默认md
if (!filename || filename.match(/.+\/$/)) {
filename = (filename || '') + 'readme.md'
}
let file = path.resolve(MARKDOWN_FILE_BASE, filename);
if (!path.parse(file).ext) {
//追加后缀
file += '.md'
}
let result = mdview.renderFile(file);
theme = theme || 'metro-lake';
return `
<!DOCTYPE html>
<html>
<head>
......@@ -31,17 +40,11 @@ function sendTemplate(filename, theme) {
`;
}
app.get('/', function (req, res) {
var query = req.query;
res.send(sendTemplate('readme.md', query.t));
})
app.get('/*.md', function(req, res){
var url = req.url, urls = url.match(/^\/([\/\w]+\.md)/), query = req.query;
res.send(sendTemplate(urls[1]||'404.md', query.t));
console.log(query)
app.get('/**', function (req, res) {
let url = req.url, urls = url.match(/^\/([\/\w]+)/) || [], query = req.query;
res.send(sendTemplate(urls[1], query.t));
})
const PORT = 3000;
app.listen(PORT)
app.listen(PORT);
console.info(`Server is started up by binding ${PORT}. Visit http://localhost:${PORT}`);
......
/*---------------------------------------------------
LESS Elements 0.9
---------------------------------------------------
A set of useful LESS mixins
More info at: http://lesselements.com
---------------------------------------------------*/
/**
* https://github.com/rhiokim/markdown-css
* made by rhio.kim
*/
::before, ::after, * {
box-sizing: border-box;
}
.metro-lake {
font-family: system, -apple-system, BlinkMacSystemFont,
"PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "STHeiti", "SimSun",
"Lucida Grande", "Lucida Sans Unicode", "Lucida Sans", 'Segoe UI',
AppleSDGothicNeo-Medium, "Malgun Gothic", Verdana, Tahoma, "Helvetica Neue", Helvetica, Arial, sans-serif;
padding: 0;
color: #333;
font-size: 0.875rem;
background: #ffffff;
-webkit-font-smoothing: antialiased;
word-wrap: break-word;
-webkit-hyphens: auto;
-ms-hyphens: auto;
hyphens: auto;
}
.metro-lake a {
color: #3269a0;
}
.metro-lake a:hover {
color: #4183c4;
}
.metro-lake blockquote {
border-left: 2px solid #666;
padding: 0 15px;
font-style: italic;
color: #777;
}
.metro-lake h1,
.metro-lake h2,
.metro-lake h3,
.metro-lake h4,
.metro-lake h5 {
font-weight: 400;
color: #444;
letter-spacing: 2px;
}
.metro-lake h1 {
text-align: center;
line-height: 2rem;
font-size: 2rem;
}
.metro-lake h2 {
font-size: 1.4rem;
border-bottom: 1px solid #bbb;
line-height: 1.6rem;
padding-bottom: 0.8rem;
text-align: center;
}
.metro-lake h2:before {
content: '══';
font-weight: 100;
letter-spacing: -1px;
padding-right: 1rem;
color: #888
}
.metro-lake h2:after {
content: '══';
font-weight: 100;
letter-spacing: -1px;
padding-left: 1rem;
color: #888
}
.metro-lake blockquote h2:before {
content: '';
padding-right: 0;
}
.metro-lake h5 {
font-weight: bold;
}
.metro-lake h6 {
color: #666;
}
.metro-lake hr {
border-top: none;
border-right: none;
border-bottom: 1px solid;
border-left: none;
border-color: #ddd;
margin: 10px 0 10px;
}
.metro-lake p {
line-height: 1.5rem;
}
.metro-lake p > code {
color: #777777;
font-size: 15px;
padding: 3px;
}
.metro-lake pre > code {
font-size: 14px;
letter-spacing: -1px;
font-weight: normal;
}
.metro-lake strong {
font-weight: 600;
}
.metro-lake table {
width: 100%;
background-color: #fafafa;
}
.metro-lake table tr th,
.metro-lake table tr td {
border: 1px solid #e6e6e6;
}
.metro-lake table tr:nth-child(2n) {
background-color: #f2f2f2;
}
/**
* after less
*/
/*
.haroopad {
img {
.bordered(@border-color, @border-color, @border-color, @border-color);
.rounded(3px);
.box-shadow(0 0 7px darken(@border-color, 18%));
&:hover {
-webkit-animation-duration: 1s;
-webkit-animation-delay: .2s;
.pulse;
}
}
h1 {
-webkit-animation-duration: .5s;
-webkit-animation-delay: .2s;
.tada;
}
&>ul {
&>li {
-webkit-animation-duration: .5s;
-webkit-animation-delay: .2s;
.fadeInLeft;
}
}
}
*/