add markdown toc

deploy
DESKTOP-4RNDQIC\29019 2021-01-13 21:13:27 +08:00
parent 04687998d6
commit c9dec3b8b1
5 changed files with 50 additions and 16 deletions

View File

@ -23,8 +23,13 @@ class Blog extends Controller
$obj['content'] = $value['content']; $obj['content'] = $value['content'];
$obj['type'] = $value['type']; $obj['type'] = $value['type'];
//数据加工 //数据加工
$markdown = new Parsedown; // $markdown = new Parsedown;
$content = $markdown->text($value['content']); // $content = $markdown->text($value['content']);
$Parsedown = new \ParsedownToC();
$content = $Parsedown->body($value['content']);
// $content = $Parsedown->contentsList();
$obj['content'] = $content; $obj['content'] = $content;
array_push($firstpagedocs,$obj); array_push($firstpagedocs,$obj);
} }
@ -57,8 +62,12 @@ class Blog extends Controller
$commentModel = new Models\DocComment(); $commentModel = new Models\DocComment();
$doc = $docModel->titleDoc(rawurldecode( $this->querys['title'])); $doc = $docModel->titleDoc(rawurldecode( $this->querys['title']));
$id = $doc[0]["id"]; $id = $doc[0]["id"];
$markdown = new Parsedown; // $markdown = new Parsedown;
$content = $markdown->text($doc[0]['content']); // $content = $markdown->text($doc[0]['content']);
$Parsedown = new \ParsedownToC();
$content = $Parsedown->body($doc[0]['content']);
$toc = $Parsedown->contentsList();
$typedocs = $docModel->getAllTypeDocs(); $typedocs = $docModel->getAllTypeDocs();
$doccoment = $commentModel->DocComments($id); $doccoment = $commentModel->DocComments($id);
$titles = $docModel->AllTitle(); $titles = $docModel->AllTitle();
@ -71,6 +80,7 @@ class Blog extends Controller
'title'=>rawurldecode($this->querys['title']), 'title'=>rawurldecode($this->querys['title']),
'index'=>false, 'index'=>false,
'content'=>$content, 'content'=>$content,
'toc'=>$toc,
'type' => $this->querys['type'], 'type' => $this->querys['type'],
'debug' => true, 'debug' => true,
'article'=>true, 'article'=>true,
@ -87,6 +97,7 @@ class Blog extends Controller
'title'=>rawurldecode($this->querys['title']), 'title'=>rawurldecode($this->querys['title']),
'article'=>true, 'article'=>true,
'content'=>$content, 'content'=>$content,
'toc'=>$toc,
'type' => $this->querys['type'], 'type' => $this->querys['type'],
"typedocs" => $typedocs, "typedocs" => $typedocs,
"comments" => $doccoment, "comments" => $doccoment,

View File

@ -82,8 +82,9 @@ class NewUi extends Controller
$groupstype = $docModel->GetAllGroupType(); $groupstype = $docModel->GetAllGroupType();
$fisrtpage = $docModel->pageDoc(5,0,55); $fisrtpage = $docModel->pageDoc(5,0,55);
$markdown = new Parsedown; $markdown = new \ParsedownToC();
$doc[0]['content'] = $markdown->text($doc[0]['content']); $doc[0]['content'] = $markdown->body($doc[0]['content']);
$doc[0]['toc'] = $markdown->contentsList();
$top5 = $docModel->top5Doc(); $top5 = $docModel->top5Doc();
foreach ($fisrtpage as $key => $value) { foreach ($fisrtpage as $key => $value) {
@ -92,7 +93,7 @@ class NewUi extends Controller
$obj['content'] = $value['content']; $obj['content'] = $value['content'];
$obj['type'] = $value['type']; $obj['type'] = $value['type'];
//数据加工 //数据加工
$content = $markdown->text($value['content']); $content = $markdown->body($value['content']);
$obj['content'] = $content; $obj['content'] = $content;
array_push($firstpagedocs,$obj); array_push($firstpagedocs,$obj);
} }
@ -141,8 +142,9 @@ class NewUi extends Controller
$commentModel = new Models\DocComment(); $commentModel = new Models\DocComment();
$doc = $docModel->titleDoc(rawurldecode($this->querys['title'])); $doc = $docModel->titleDoc(rawurldecode($this->querys['title']));
$id = $doc[0]["id"]; $id = $doc[0]["id"];
$markdown = new Parsedown; $markdown = new \ParsedownToC();
$doc[0]['content'] = $markdown->text($doc[0]['content']); $doc[0]['content'] = $markdown->body($doc[0]['content']);
$typedocs = $docModel->getAllTypeDocs(); $typedocs = $docModel->getAllTypeDocs();
$doccoment = $commentModel->DocComments($id); $doccoment = $commentModel->DocComments($id);
$titles = $docModel->AllTitle(); $titles = $docModel->AllTitle();

View File

@ -1,5 +1,5 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html xmlns="http://www.w3.org/1999/html">
<head> <head>
<title>{{ title }}</title> <title>{{ title }}</title>
<link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css"> <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
@ -13,6 +13,14 @@
<script src="/api/App/Views/blog/js//jquery-editable-select.min.js"></script> <script src="/api/App/Views/blog/js//jquery-editable-select.min.js"></script>
<script src="/api/App/Views/blog/js//bootstrap-treeview.min.js"></script> <script src="/api/App/Views/blog/js//bootstrap-treeview.min.js"></script>
<link href="/api/App/Views/blog/css/jquery-editable-select.min.css" rel="stylesheet"> <link href="/api/App/Views/blog/css/jquery-editable-select.min.css" rel="stylesheet">
<style type="text/css">
#doc_toc ul {
margin-left: -15px;
}
#doc_toc ul li {
color: #8e846b;
}
</style>
</head> </head>
<body style="background: #eee"> <body style="background: #eee">
@ -148,7 +156,11 @@
<!--评论列表显示区end--> <!--评论列表显示区end-->
</div> </div>
</div> </div>
<div class="col-md-1" style="padding: 0px;margin-left: -10px; " id="doc_toc" >
{{ doc.toc| raw }}
</div>
</div> </div>
<div class="row"> <div class="row">
<ul class="pagination" style="margin-left: 50%" id="pagenation"> <ul class="pagination" style="margin-left: 50%" id="pagenation">
<li><a href="#">&laquo;</a></li> <li><a href="#">&laquo;</a></li>
@ -219,7 +231,6 @@
}); });
} }
function loadtypedoc(data){ function loadtypedoc(data){
console.log(data.href.split("#")[1].split("doc_type_")[1]);
chosetype = data.href.split("#")[1].split("doc_type_")[1]; chosetype = data.href.split("#")[1].split("doc_type_")[1];
$.ajax({ $.ajax({
method: "POST", method: "POST",
@ -274,7 +285,9 @@
{ {
if(globalposx > 250){ if(globalposx > 250){
$('#grouptab').fadeOut(1000); $('#grouptab').fadeOut(1000);
$('#doc_toc').fadeIn(1000);
} }
} }
$(document).ready( $(document).ready(
function () { function () {
@ -311,7 +324,8 @@
$(document).mousemove(function(e){ $(document).mousemove(function(e){
if(e.pageX < 250){ if(e.pageX < 250){
$('#grouptab').fadeIn(2000); $('#grouptab').fadeIn(1500);
$('#doc_toc').fadeOut(1000);
} }
if(e.pageX < 400){ if(e.pageX < 400){
$('#doctype').fadeIn(2000); $('#doctype').fadeIn(2000);

View File

@ -11,6 +11,12 @@
<script src="/api/App/Views/blog/js//jquery-editable-select.min.js"></script> <script src="/api/App/Views/blog/js//jquery-editable-select.min.js"></script>
<script src="/api/App/Views/blog/js//bootstrap-treeview.min.js"></script> <script src="/api/App/Views/blog/js//bootstrap-treeview.min.js"></script>
<link href="/api/App/Views/blog/css/jquery-editable-select.min.css" rel="stylesheet"> <link href="/api/App/Views/blog/css/jquery-editable-select.min.css" rel="stylesheet">
<script type="text/css">
#doc_toc > ul{
margin-left: -30px;
color: black;
}
</script>
</head> </head>
<body style="background: #eee"> <body style="background: #eee">

View File

@ -2,13 +2,14 @@
"require": { "require": {
"twig/twig": "~2.0", "twig/twig": "~2.0",
"propel/propel": "~2.0@dev", "propel/propel": "~2.0@dev",
"erusev/parsedown": "^1.7" "erusev/parsedown": "^1.7",
"hoegh/parsedown-toc": "^1.3"
}, },
"repositories": { "repositories": {
"packagist": { "packagist": {
"type": "composer", "type": "composer",
"url": "https://packagist.phpcomposer.com" "url": "https://mirrors.aliyun.com/composer/"
} }
}, },
"autoload": { "autoload": {
"psr-4": { "psr-4": {