1
0
mirror of https://github.com/osmarks/mycorrhiza.git synced 2024-12-12 05:20:26 +00:00

Themes, Dark theme

This commit is contained in:
Dan Konshin 2020-06-24 17:21:48 +05:00
parent 753d63c70a
commit 56541c9d30
39 changed files with 694 additions and 94 deletions

View File

@ -19,12 +19,13 @@ var (
TitleTemplate = `%s`
GenericErrorMsg = `<b>Sorry, something went wrong</b>`
SiteTitle = `MycorrhizaWiki`
Theme = `default-light`
)
func InitConfig(wd string) bool {
log.Println("WikiDir is", wd)
WikiDir = wd
TemplatesDir = filepath.Join(filepath.Dir(WikiDir), "templates")
TemplatesDir = "Templates"
configJsonPath = filepath.Join(filepath.Dir(WikiDir), "config.json")
if _, err := os.Stat(configJsonPath); os.IsNotExist(err) {
@ -46,6 +47,7 @@ func readConfig() bool {
cfg := struct {
Address string `json:"address"`
Theme string `json:"theme"`
SiteTitle string `json:"site-title"`
TitleTemplates struct {
EditHypha string `json:"edit-hypha"`
@ -60,6 +62,7 @@ func readConfig() bool {
}
Address = cfg.Address
Theme = cfg.Theme
SiteTitle = cfg.SiteTitle
TitleEditTemplate = cfg.TitleTemplates.EditHypha
TitleTemplate = cfg.TitleTemplates.ViewHypha

View File

@ -69,8 +69,9 @@ func renderBase(content string, keys map[string]string) string {
// renderFromMap applies `data` map to template in `templatePath` and returns the result.
func renderFromMap(data map[string]string, templatePath string) string {
filePath := path.Join(cfg.TemplatesDir, templatePath)
tmpl, err := template.ParseFiles(filePath)
hyphPath := path.Join(cfg.TemplatesDir, cfg.Theme, templatePath)
rev, _ := GetRevision(hyphPath, "0")
tmpl, err := template.ParseFiles(rev.TextPath)
if err != nil {
return err.Error()
}
@ -83,8 +84,9 @@ func renderFromMap(data map[string]string, templatePath string) string {
// renderFromMap applies `data` string to template in `templatePath` and returns the result.
func renderFromString(data string, templatePath string) string {
filePath := path.Join(cfg.TemplatesDir, templatePath)
tmpl, err := template.ParseFiles(filePath)
hyphPath := path.Join(cfg.TemplatesDir, cfg.Theme, templatePath)
rev, _ := GetRevision(hyphPath, "0")
tmpl, err := template.ParseFiles(rev.TextPath)
if err != nil {
return err.Error()
}

View File

@ -1,5 +1,6 @@
{
"address": "127.0.0.1:1737",
"theme": "default-dark",
"site-title": "🍄 MycorrhizaWiki",
"title-templates": {
"edit-hypha": "Edit %s at MycorrhizaWiki",

View File

@ -0,0 +1,17 @@
{
"views": 0,
"deleted": false,
"revisions": {
"1": {
"tags": null,
"name": "header.html",
"comment": "Create Templates/default-dark/Hypha/edit/header.html",
"author": "",
"time": 1592996801,
"text_mime": "text/html",
"binary_mime": "",
"text_name": "1.html",
"binary_name": ""
}
}
}

View File

@ -0,0 +1,17 @@
{
"views": 0,
"deleted": false,
"revisions": {
"1": {
"tags": null,
"name": "index.html",
"comment": "Create Templates/default-dark/Hypha/edit/index.html",
"author": "",
"time": 1592996876,
"text_mime": "text/html",
"binary_mime": "",
"text_name": "1.html",
"binary_name": ""
}
}
}

View File

@ -0,0 +1,17 @@
{
"views": 0,
"deleted": false,
"revisions": {
"1": {
"tags": null,
"name": "404.html",
"comment": "Create Templates/default-light/Hypha/view/404.html",
"author": "",
"time": 1592996917,
"text_mime": "text/html",
"binary_mime": "",
"text_name": "1.html",
"binary_name": ""
}
}
}

View File

@ -0,0 +1,17 @@
{
"views": 0,
"deleted": false,
"revisions": {
"1": {
"tags": null,
"name": "index.html",
"comment": "Create Templates/default-light/Hypha/view/index.html",
"author": "",
"time": 1592996954,
"text_mime": "text/html",
"binary_mime": "",
"text_name": "1.html",
"binary_name": ""
}
}
}

View File

@ -0,0 +1,17 @@
{
"views": 0,
"deleted": false,
"revisions": {
"1": {
"tags": null,
"name": "sidebar.html",
"comment": "Create Templates/default-light/Hypha/view/sidebar.html",
"author": "",
"time": 1592996977,
"text_mime": "text/html",
"binary_mime": "",
"text_name": "1.html",
"binary_name": ""
}
}
}

View File

@ -1,7 +1,7 @@
<html>
<head>
<title>{{ .Title }}</title>
<link rel="stylesheet" href="/sys/main.css?action=raw">
<link rel="stylesheet" href="/Templates/default-dark/main.css?action=raw">
</head>
<body>
<div class="shroom">
@ -25,6 +25,6 @@
</div>
</div>
</div>
<script src="/sys/main.js?action=raw"></script>
<script src="/Templates/default-dark/main.js?action=raw"></script>
</body>
</html>

View File

@ -0,0 +1,17 @@
{
"views": 0,
"deleted": false,
"revisions": {
"1": {
"tags": null,
"name": "base.html",
"comment": "Create Templates/default-dark/base.html",
"author": "",
"time": 1592996503,
"text_mime": "text/html",
"binary_mime": "",
"text_name": "1.html",
"binary_name": ""
}
}
}

View File

@ -0,0 +1,224 @@
*, *::before, *::after {
box-sizing: border-box;
}
html {
height: 100%;
}
body {
font: 15px/1.5 system-ui, -apple-system, BlinkMacSystemFont, 'Helvetica Neue', 'Helvetica', 'PT Sans', 'Roboto', 'Arial', sans-serif;
max-width: 500px;
min-height: 100%;
margin: 0 auto;
padding: 12px 24px;
background-color: #272b30;
color: #c8c8c8;
}
.msg {
background-color: #f4f4f4;
padding: 1rem;
border-radius: 1rem;
}
.shroom {
margin: 0;
}
.shroom__button {
border-radius: 1rem;
padding: 8px 16px 8px 0;
border: none;
background: #f0f2f4;
color: #444;
font: inherit;
font-size: 15px;
font-weight: 500;
text-align: left;
}
.shroom span {
margin-left: 16px;
margin-right: 8px;
font-size: 20px;
vertical-align: -0.04em;
}
.mushroom .shroom__button {
background: #44484a;
color: #dddfe4;
}
.header {
padding: 8px 0;
}
.header h1 {
margin: 0;
font-size: 18px;
font-weight: 600;
letter-spacing: 0.02em;
color: #20ce92;
}
a {
color: #019fe3;
}
/*a:visited {
color: #44a;
}*/
h1, h2, h3, h4, h5, h6 {
margin: 0.5em 0 0.25em;
}
.page {
font-size: 16px;
line-height: 1.666;
max-width: 40em;
hyphens: auto;
}
.page pre {
white-space: break-spaces;
}
.page__amnt {
max-width: 100%;
}
.page__title {
font-family: 'PT Serif', 'Georgia', serif;
font-size: 36px;
font-weight: normal;
color: #20ce92;
}
.edit-box {
display: grid;
grid-template-columns: 7fr 5fr;
}
.edit-box .naviwrapper__buttons {
grid-column: 1;
grid-row: 2;
}
.edit-box__left { grid-column: 1; grid-row: 2 }
.edit-box__right { grid-column: 2; grid-row: 1 / span 2; padding-right: 16px }
footer {
padding: 1em 0;
font-size: 12px;
color: #7a8288;
}
footer a, footer a:visited {
color: #7a8288;
}
.left-panel {
display: none;
}
.left-panel.active {
display: block;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background: #fafafa;
}
.left-panel.active .sidebar {
background: #fff;
}
.left-panel__in {
width: 100%;
height: 100%;
max-width: 500px;
margin: 0 auto;
padding: 12px 24px;
}
.left-panel__contents {
width: 100%;
display: grid;
grid-template-rows: auto 1fr auto;
}
.left-panel .shroom {
margin-bottom: 16px;
}
@media (min-width: 700px) {
body {
max-width: 1200px;
padding: 8px 16px;
padding-right: 274px;
}
.shroom {
display: none;
}
.page {
font-size: 18px;
}
.left-panel {
display: block;
position: fixed;
top: 0;
bottom: 0;
width: 274px;
right: 0;
}
.left-panel__contents {
height: 100%;
}
}
.sidebar {
padding: 16px 0;
border-radius: 1rem;
background-color: rgba(255,255,255,.05);
}
.hypha-actions ul {
margin: 0;
padding: 0;
}
.hypha-actions li {
list-style: none;
}
.hypha-actions a {
display: block;
padding: 6px 16px;
font: inherit;
text-decoration: none;
color: #7a8288;
transition: 0.1s background;
}
aside .hypha-actions a:hover {
background: #eaeaea;
}

View File

@ -0,0 +1,17 @@
{
"views": 0,
"deleted": false,
"revisions": {
"1": {
"tags": null,
"name": "updateOk.html",
"comment": "Create Templates/default-dark/updateOk.html",
"author": "",
"time": 1592996644,
"text_mime": "text/html",
"binary_mime": "",
"text_name": "1.html",
"binary_name": ""
}
}
}

View File

@ -0,0 +1 @@
<h1 class="header__edit-title">Edit {{ . }}</h1>

View File

@ -0,0 +1,17 @@
{
"views": 0,
"deleted": false,
"revisions": {
"1": {
"tags": null,
"name": "header.html",
"comment": "Create Templates/default-light/Hypha/edit/header.html",
"author": "",
"time": 1592996801,
"text_mime": "text/html",
"binary_mime": "",
"text_name": "1.html",
"binary_name": ""
}
}
}

View File

@ -0,0 +1,36 @@
<div class="naviwrapper">
<form class="naviwrapper__edit edit-box"
method="POST"
enctype="multipart/form-data"
action="?action=update">
<div class="naviwrapper__buttons">
<input type="submit" value="update"/>
</div>
<div class="edit-box__left">
<h4>Edit box</h4>
<!-- It is important that there is no indent ↓ -->
<textarea class="edit-box__text" name="text" cols="80" rows="25">
{{ .Text }}
</textarea>
<h4>Upload file</h4>
<p>If this hypha has a file like that, the text above is meant to be a description of it</p>
<input type="file" name="binary"/>
</div>
<div class="edit-box__right">
<h4>Text MIME-type</h4>
<p>Good types are <code>text/markdown</code> and <code>text/plain</code></p>
<input type="text" name="text_mime" value="{{ .TextMime }}"/>
<h4>Revision comment</h4>
<p>Please make your comment helpful</p>
<input type="text" name="comment" value="Update {{ .Name }}"/>
<h4>Edit tags</h4>
<p>Tags are separated by commas, whitespace is ignored</p>
<input type="text" name="tags" value="{{ .Tags }}"/>
</div>
</form>
</div>

View File

@ -0,0 +1,17 @@
{
"views": 0,
"deleted": false,
"revisions": {
"1": {
"tags": null,
"name": "index.html",
"comment": "Create Templates/default-light/Hypha/edit/index.html",
"author": "",
"time": 1592996876,
"text_mime": "text/html",
"binary_mime": "",
"text_name": "1.html",
"binary_name": ""
}
}
}

View File

@ -0,0 +1,4 @@
<h1 class="page__title">{{ . }}</h1>
<p class="msg_hypha-does-not-exist msg">
The hypha you are trying to access does not exist yet. Why not <a href="?action=edit">create</a> it?
</p>

View File

@ -0,0 +1,17 @@
{
"views": 0,
"deleted": false,
"revisions": {
"1": {
"tags": null,
"name": "404.html",
"comment": "Create Templates/default-light/Hypha/view/404.html",
"author": "",
"time": 1592996917,
"text_mime": "text/html",
"binary_mime": "",
"text_name": "1.html",
"binary_name": ""
}
}
}

View File

@ -0,0 +1 @@
{{ . }}

View File

@ -0,0 +1,17 @@
{
"views": 0,
"deleted": false,
"revisions": {
"1": {
"tags": null,
"name": "index.html",
"comment": "Create Templates/default-light/Hypha/view/index.html",
"author": "",
"time": 1592996954,
"text_mime": "text/html",
"binary_mime": "",
"text_name": "1.html",
"binary_name": ""
}
}
}

View File

@ -0,0 +1,9 @@
<div class="hypha-actions">
<ul>
<li><a href="?action=edit">Edit</a></li>
<li><a href="?action=getBinary">Download</a></li>
<li><a href="?action=zen">Zen mode</a></li>
<li><a href="?action=raw">View raw</a></li>
</ul>
</div>
{{ .Tree }}

View File

@ -0,0 +1,17 @@
{
"views": 0,
"deleted": false,
"revisions": {
"1": {
"tags": null,
"name": "sidebar.html",
"comment": "Create Templates/default-light/Hypha/view/sidebar.html",
"author": "",
"time": 1592996977,
"text_mime": "text/html",
"binary_mime": "",
"text_name": "1.html",
"binary_name": ""
}
}
}

View File

@ -0,0 +1,30 @@
<html>
<head>
<title>{{ .Title }}</title>
<link rel="stylesheet" href="/Templates/default-light/main.css?action=raw">
</head>
<body>
<div class="shroom">
<button class="shroom__button" id="shroomBtn"><span>🍄</span> Open</button>
</div>
<main class="main">{{ .Main }}</main>
<div class="left-panel" id="shroomburgerMenu">
<div class="left-panel__in">
<div class="shroom mushroom">
<button class="shroom__button" id="mushroomBtn"><span>🍄</span> Close</button>
</div>
<div class="left-panel__contents">
<!-- Site title is fetched from your config.json. Set your title in "site-title" field. You can add more things to the header here. -->
<header class="header">
<h1 class="header__site-title">{{ .SiteTitle }}</h1>
</header>
<aside class="sidebar">{{ .Sidebar }}</aside>
<footer class="footer">
<p>This website runs <a href='https://github.com/bouncepaw/mycorrhiza'>MycorrhizaWiki</a></p>
</footer>
</div>
</div>
</div>
<script src="/Templates/default-light/main.js?action=raw"></script>
</body>
</html>

View File

@ -0,0 +1,17 @@
{
"views": 0,
"deleted": false,
"revisions": {
"1": {
"tags": null,
"name": "base.html",
"comment": "Create Templates/default-light/base.html",
"author": "",
"time": 1592996503,
"text_mime": "text/html",
"binary_mime": "",
"text_name": "1.html",
"binary_name": ""
}
}
}

View File

@ -0,0 +1,19 @@
{
"views": 0,
"deleted": false,
"revisions": {
"1": {
"tags": [
""
],
"name": "main.css",
"comment": "Update sys/main.css",
"author": "",
"time": 1592666188,
"text_mime": "text/css",
"binary_mime": "",
"text_name": "1.css",
"binary_name": ""
}
}
}

View File

@ -0,0 +1,7 @@
var menu = document.getElementById('shroomburgerMenu');
document.getElementById('shroomBtn').addEventListener('click', function() {
menu.classList.add('active');
});
document.getElementById('mushroomBtn').addEventListener('click', function() {
menu.classList.remove('active');
});

View File

@ -0,0 +1,17 @@
{
"views": 0,
"deleted": false,
"revisions": {
"1": {
"tags": null,
"name": "main.js",
"comment": "Update sys/main.js",
"author": "",
"time": 1592937088,
"text_mime": "text/javascript",
"binary_mime": "",
"text_name": "1.mjs",
"binary_name": ""
}
}
}

View File

@ -0,0 +1,8 @@
<html>
<head>
<title>Saved {{ .Name }}</title>
</head>
<body>
<p>Saved successfully. <a href="/{{ .Name }}">Go back</a></p>
</body>
</html>

View File

@ -0,0 +1,17 @@
{
"views": 0,
"deleted": false,
"revisions": {
"1": {
"tags": null,
"name": "updateOk.html",
"comment": "Create Templates/default-light/updateOk.html",
"author": "",
"time": 1592996644,
"text_mime": "text/html",
"binary_mime": "",
"text_name": "1.html",
"binary_name": ""
}
}
}