Neue Funktion: Das Datum der letzten änderung würd jetzt unten rechts angezeigt.

Außerdem etwas Code aufgeräumt.
This commit is contained in:
Sven Schmalle 2019-12-20 12:55:43 +01:00
parent 3be67ae665
commit 3dfcf7e237
2 changed files with 65 additions and 16 deletions

22
main.go
View File

@ -102,6 +102,7 @@ func main() {
router := mux.NewRouter()
router.HandleFunc("/_api/md/{pagename:.*}", getRawPage).Methods("GET")
router.HandleFunc("/_api/pdf/{pagename:.*}", getPDFPage).Methods("GET")
router.HandleFunc("/_api/pinfo/{pagename:.*}", getPageInfo).Methods("GET")
router.HandleFunc("/_api/fts/{searchterm:.*}", getFTS).Methods("GET")
router.HandleFunc("/{pagename:.*}", getHTMLPage).Methods("GET")
router.HandleFunc("/{pagename:.*}", postHTMLPage).Methods("POST")
@ -269,6 +270,27 @@ func getFTS(w http.ResponseWriter, r *http.Request) {
}
}
func getPageInfo(w http.ResponseWriter, r *http.Request) {
params := mux.Vars(r)
pPageName := params["pagename"] + ".md"
f, err := os.Open(path.Join(config.DataPath, pPageName))
check(err)
statinfo, err := f.Stat()
check(err)
data := struct {
PageName string
ModTime time.Time
}{
pPageName,
statinfo.ModTime(),
}
json.NewEncoder(w).Encode(data)
}
//--------------------------------------------------------------------------
// Typen
//--------------------------------------------------------------------------

View File

@ -134,8 +134,7 @@
<div class="container-fluid">
<div class="d-flex flex-row">
<div id="sidebar" class="p-2 sidebar">
<!-- <div id="outputsidebar" style="display: none;">{{.SideBar}}</div> -->
<div id="outputsidebar">{{.SideBar}}</div>
<div id="outputsidebar" style="display: none;">{{.SideBar}}</div>
</div>
<div id="main" class="p-2 main">
<div id="markdowndiv" style="display: none;">{{.MDText}}</div>
@ -143,6 +142,7 @@
<div id="editdiv" style="display: none;">
<form><textarea id="code" name="code"></textarea>
</div>
<div id="ModificationInfos" style="position:fixed;top:98%;right:1%"></div>
</div>
</div>
</div>
@ -157,13 +157,13 @@
var html = "EMPTY";
var MD2HTMLConverter = new showdown.Converter({
tables: true,
strikethrough: true,
simplifiedAutoLink: true,
excludeTrailingPunctuationFromURLs: true,
tasklists: true,
emoji: true
});
tables: true,
strikethrough: true,
simplifiedAutoLink: true,
excludeTrailingPunctuationFromURLs: true,
tasklists: true,
emoji: true
});
$(document).ready(function() {
@ -172,9 +172,8 @@
$(btnPreviewpage).hide();
//html = converter.makeHtml($("#outputdiv").html());
//$("#outputdiv").html(html);
//-----------------------------------------------------------------------------------
// Breadcrump Navigation im Header
var breadcrumbHTML = "";
var sPageURL = window.location.pathname.split('/');
@ -190,7 +189,8 @@
$("#breadcrumb").html(breadcrumbHTML);
//-----------------------------------------------------------------------------------
// Codemirror Editor
window.myCodeMirror = CodeMirror.fromTextArea(document.getElementById("code"), {
mode: 'markdown',
lineNumbers: true,
@ -203,7 +203,8 @@
window.myCodeMirror.refresh();
});
//-----------------------------------------------------------------------------------
// Laden des Outputdiv (HTML Anzeige des MD-Textes)
$.ajax({
method: "GET",
contentType:'application/json; charset=utf-8',
@ -218,7 +219,8 @@
}
});
//-----------------------------------------------------------------------------------
// Laden der sidebar.md in die Sidebar
$.ajax({
method: "GET",
contentType:'application/json; charset=utf-8',
@ -232,6 +234,12 @@
}
});
//-----------------------------------------------------------------------------------
ajaxLoadModificationInfos(window.location.pathname);
//-----------------------------------------------------------------------------------
// Volltext-Suche
$('#srch-term').keypress(function (e) {
if (e.which == 13) {
//alert($('#srch-term').val());
@ -277,7 +285,7 @@
// Observe one or multiple elements
ro.observe(document.querySelector('#outputsidebar'));
//-----------------------------------------------------------------------------------
});
function EditPage() {
@ -329,6 +337,8 @@
$(btnEditpage).show();
$(btnSavepage).hide();
$(btnPreviewpage).hide();
ajaxLoadModificationInfos(window.location.pathname);
}
});
}
@ -338,6 +348,23 @@
window.open('/_api/pdf'+window.location.pathname);
}
function ajaxLoadModificationInfos(page) {
// Laden des ModificationInfos-Div (Anzeige der letzten Änderung an der Seite)
$.ajax({
method: "GET",
contentType:'application/json; charset=utf-8',
url: '/_api/pinfo/'+page,
dataType: "json",
data: "",
success: function(content){
//date = new Intl.DateTimeFormat('de-DE').format(new Date(content.ModTime));
date = new Date(content.ModTime).toLocaleString('de-DE');
$("#ModificationInfos").html("<p><small>Letzte änderung: "+date+"</small></p>");
$("#ModificationInfos").show();
}
});
}
</script>
<script>
//--------------------------------------------------------------------------