Add sidebar
This commit is contained in:
parent
1f105eff39
commit
556f462a2d
|
@ -191,25 +191,25 @@ function renderGraphs() {
|
|||
})
|
||||
}
|
||||
|
||||
if (holder) {
|
||||
const MD = new MarkdownIt({
|
||||
linkify: true,
|
||||
highlight: function (str, lang) {
|
||||
if (lang === 'mermaid') {
|
||||
return '<div class="mermaid">' + str + '</div>';
|
||||
}
|
||||
return '';
|
||||
const MD = new MarkdownIt({
|
||||
linkify: true,
|
||||
highlight: function (str, lang) {
|
||||
if (lang === 'mermaid') {
|
||||
return '<div class="mermaid">' + str + '</div>';
|
||||
}
|
||||
})
|
||||
MD.use(MarkdownItWikilinks({
|
||||
baseURL: holder.dataset.baseUrl,
|
||||
uriSuffix: '',
|
||||
relativeBaseURL: '/edit/',
|
||||
htmlAttributes: {
|
||||
class: 'wiki-link'
|
||||
},
|
||||
})).use(MarkdownItMark).use(MarkdownItKatex)
|
||||
return '';
|
||||
}
|
||||
})
|
||||
MD.use(MarkdownItWikilinks({
|
||||
baseURL: document.querySelector('body').dataset.baseUrl,
|
||||
uriSuffix: '',
|
||||
relativeBaseURL: '/edit/',
|
||||
htmlAttributes: {
|
||||
class: 'wiki-link'
|
||||
},
|
||||
})).use(MarkdownItMark).use(MarkdownItKatex)
|
||||
|
||||
if (holder) {
|
||||
const options = {
|
||||
transform(text, element) {
|
||||
let converted = text
|
||||
|
@ -489,3 +489,10 @@ search(searchInput).then(searcher => {
|
|||
return true
|
||||
})
|
||||
})
|
||||
|
||||
document.querySelectorAll(".page-loader")
|
||||
.forEach((el, key, parent) => {
|
||||
fetch('/' + el.dataset.page + '?format=markdown').then(res => res.text()).then(text => {
|
||||
el.innerHTML = MD.render(text)
|
||||
})
|
||||
})
|
||||
|
|
|
@ -207,3 +207,17 @@ mark {
|
|||
.marker, .fold {
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
.grid {
|
||||
display: grid;
|
||||
grid-template-columns: 300px auto;
|
||||
|
||||
.sidebar {
|
||||
padding: 0 12px;
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
|
||||
.section {
|
||||
padding: 0;
|
||||
}
|
||||
|
|
25
main.go
25
main.go
|
@ -151,6 +151,8 @@ type recentPage struct {
|
|||
Recent []Change
|
||||
}
|
||||
|
||||
var baseTemplate = []string{"templates/layout.html", "templates/sidebar.html"}
|
||||
|
||||
type indexHandler struct{}
|
||||
type graphHandler struct{}
|
||||
type saveHandler struct {
|
||||
|
@ -177,7 +179,9 @@ func (*authHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
if r.Method == http.MethodGet {
|
||||
if r.URL.Path == "/auth/login" {
|
||||
t, err := template.ParseFiles("templates/layout.html", "templates/login.html")
|
||||
templates := baseTemplate
|
||||
templates = append(templates, "templates/login.html")
|
||||
t, err := template.ParseFiles(templates...)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), 500)
|
||||
return
|
||||
|
@ -215,7 +219,9 @@ func (*authHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||
http.Redirect(w, r, sess.NextURI, 302)
|
||||
return
|
||||
} else if r.URL.Path == "/auth/logout" {
|
||||
t, err := template.ParseFiles("templates/layout.html", "templates/logout.html")
|
||||
templates := baseTemplate
|
||||
templates = append(templates, "templates/logout.html")
|
||||
t, err := template.ParseFiles(templates...)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), 500)
|
||||
return
|
||||
|
@ -459,8 +465,9 @@ func (h *editHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||
TodayPage: todayPage(),
|
||||
ShowGraph: page != "Daily_Notes",
|
||||
}
|
||||
|
||||
t, err := template.ParseFiles("templates/layout.html", "templates/edit.html")
|
||||
templates := baseTemplate
|
||||
templates = append(templates, "templates/edit.html")
|
||||
t, err := template.ParseFiles(templates...)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), 500)
|
||||
return
|
||||
|
@ -540,8 +547,9 @@ func (h *graphHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||
Nodes: template.JS(nodesBuf.String()),
|
||||
Edges: template.JS(edgesBuf.String()),
|
||||
}
|
||||
|
||||
t, err := template.ParseFiles("templates/layout.html", "templates/graph.html")
|
||||
templates := baseTemplate
|
||||
templates = append(templates, "templates/graph.html")
|
||||
t, err := template.ParseFiles(templates...)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), 500)
|
||||
return
|
||||
|
@ -670,8 +678,9 @@ func (h *indexHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||
ShowGraph: page != "Daily_Notes",
|
||||
TodayPage: todayPage(),
|
||||
}
|
||||
|
||||
t, err := template.ParseFiles("templates/layout.html", "templates/view.html")
|
||||
templates := baseTemplate
|
||||
templates = append(templates, "templates/view.html")
|
||||
t, err := template.ParseFiles(templates...)
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), 500)
|
||||
return
|
||||
|
|
|
@ -225,7 +225,7 @@
|
|||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<body data-base-url="{{ .BaseURL }}">
|
||||
<div>
|
||||
<nav class="navbar" role="navigation" aria-label="main navigation">
|
||||
<div class="navbar-brand">
|
||||
|
@ -262,9 +262,14 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<section class="section">
|
||||
{{ template "content" . }}
|
||||
</section>
|
||||
<div class="grid">
|
||||
{{ template "sidebar" . }}
|
||||
|
||||
<section class="section">
|
||||
{{ template "content" . }}
|
||||
</section>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="h-app">
|
||||
<a href="/" class="u-url p-name">Wiki</a>
|
||||
|
|
3
templates/sidebar.html
Normal file
3
templates/sidebar.html
Normal file
|
@ -0,0 +1,3 @@
|
|||
{{ define "sidebar" }}
|
||||
<div class="sidebar page-loader content" data-page="Sidebar"></div>
|
||||
{{ end }}
|
Loading…
Reference in New Issue
Block a user