❝本文收錄於 GitHub 山月行博客: shfshanyue/blog,內含我在實際工做中碰到的問題、關於業務的思考及在全棧方向上的學習html
❞
前端工程化系列 Node進階系列
藉助於優秀的開源工具 mdnice
,根據 mardown
生成美化 html
的 GraphQL API 服務。前端
快來試一試效果~web
API
mardown to html
❝快來在 GraphQL Playground 中試一試效果面試
❞
query HTML (
$markdown: String!
$endpoint: String
$theme: String
$formatType: FormatType
) {
html (
markdown: $markdown,
browserWSEndpoint: $endpoint,
theme: $theme
formatType: $formatType
)
}
其中:chrome
-
markdown
: 必填,你須要轉換的 markdown 內容 -
endpoint
: 選填,browserless 中的服務接口,也可自建服務,默認值爲wss://chrome.browserless.io/
-
theme
: 選填,mdnice 中的主題名稱,默認爲薔薇紫
-
formatType
: 選填,可選[JUEJIN | WECHAT | ZHIHU ]
,轉換後 html 適應各平臺的格式,默認爲JUEJIN
示例以下:express
{
"markdown": "## Hello, shanyue",
"endpoint": "wss://chrome.shanyue.tech",
"theme": "全棧藍",
"formatType": "WECHAT"
}
Develop
能夠經過如下方式快速基於此項目開發,並歡迎提交 PR 及 Forknpm
# 本地啓動,快速調試項目
$ npm run dev
# 調試 pptr
$ DEBUG=* npm run dev
# 在本地瀏覽器調試 pptr (在本地調試時若是不是 MAC,須要手動指定 chrome 位置)
$ DEBUG=1 npm run dev
Deploy
本項目部署在騰訊雲 serverless 中,在部署前能夠指定如下環境變量,如未指定,則默認環境變量取如下的值前端工程化
# browserless 的服務入口地址,可以使用本身的付費地址或自建
DEFAULT_ENDPOINT="wss://chrome.browserless.io/"
# mdnice 官網地址
MD_NICE="https://mdnice.com"
其中:api
-
DEFAULT_ENDPOINT
: browserless 中的服務接口,也可自建服務,默認值爲wss://chrome.browserless.io/
-
MD_NICE
: mdnice 地址,可自建服務
快速部署:跨域
$ npm i -g serverless
$ sls --debug
部署資源配置文件 serverless.yml
因爲是高延遲服務,記得把函數超時及網關超時設置到 200s,以下所示:
component: express # (required) name of the component. In that case, it's express.
name: markdown-to-html-api
org: shanyue
inputs:
src: ./ # (optional) path to the source folder. default is a hello world app.
functionName: mardown-api
region: ap-shanghai
runtime: Nodejs12.16
exclude:
- .env
functionConf:
timeout: 200
memorySize: 128
apigatewayConf:
protocols:
- http
- https
environment: release
enableCORS: true # 容許跨域
serviceTimeout: 200
關於我
❝本文收錄於 GitHub 山月行博客: shfshanyue/blog,內含我在實際工做中碰到的問題、關於業務的思考及在全棧方向上的學習
❞
前端工程化系列 Node進階系列碼添加個人微信,備註進羣,加入高級前端進階羣
![](http://static.javashuo.com/static/loading.gif)
歡迎關注公衆號【全棧成長之路】,定時推送 Node 原創及全棧成長文章
![](http://static.javashuo.com/static/loading.gif)
本文分享自微信公衆號 - 全棧成長之路(shanyue-road)。
若有侵權,請聯繫 support@oschina.cn 刪除。
本文參與「OSC源創計劃」,歡迎正在閱讀的你也加入,一塊兒分享。