我正在嘗試將 Markdown 檔案加載為靜態檔案,然后應通過 html 檔案呈現該檔案。我現在的問題是如何應用 CSS 樣式。這是我的index.js代碼:
const express = require('express');
const bodyparser = require('body-parser');
const showdown = require('showdown');
const marked = require('marked');
const app = express()
app.use(express.static(__dirname '/'));
app.use(bodyparser.urlencoded({extend:true}));
app.engine('html', require('ejs').renderFile);
app.set('view engine', 'html');
app.set('views', __dirname);
app.use(express.static('public'));
app.get('/article', (req,res)=> {
var markdown = require("markdown-js");
var fs = require("fs");
var path = __dirname 'articles/article.md'
app.use(express.static("public"));
fs.readFile(path, 'utf8', function(err, data) {
if(err) {
console.log(err);
}
//res.send(marked("" data));
//console.log(result);
res.render('index.html');
});
});
// listen to port
const PORT= 3000;
app.listen(process.env.PORT || 3000, function(){
console.log('server is running on port 3000');
})
我當前 html 檔案的代碼如下所示index.html:
<!DOCTYPE html>
<html lang="en">
<script src="style.css"></script>
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<% result %>
</body>
</html>
uj5u.com熱心網友回復:
為了使用你必須使用的變數,ejs你可以在這里閱讀它https://ejs.co/
那么你可以做這樣的事情:
- 先把名字改成
index.ejs - 然后你必須傳遞資料
res.render("index", { result: data })
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/362139.html
標籤:javascript css 节点.js
