Skip to content

Commit

Permalink
add logo
Browse files Browse the repository at this point in the history
  • Loading branch information
pilcrowOnPaper committed May 9, 2024
1 parent 4bd042d commit a32af84
Show file tree
Hide file tree
Showing 6 changed files with 200 additions and 140 deletions.
8 changes: 6 additions & 2 deletions docs/pages/basics/setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ install <platform>-<arch>/malta /usr/local/bin

## Create a config file

Create `malta.config.json` in the project root.
Create `malta.config.json` in the project root.

```json
{
Expand All @@ -31,10 +31,14 @@ Create `malta.config.json` in the project root.

// optional
"twitter": "@pilcrowonpaper", // twitter account associated with the project
"sidebar" [] // see 'Sidebar' page
"sidebar" [], // see 'Sidebar' page
"logo": "logo.svg", //for sidebar (must be the name of a file in the same dir)
"og_logo": "og_logo.png" // square image of OG (must be the name of a file in the same dir)
}
```

You can also add a `favicon.ico` next to the config.

## Create `pages` directory

Create a `pages` directory next to the config file, and create `index.md`. You must have a `title` attribute.
Expand Down
10 changes: 10 additions & 0 deletions src/commands/build/assets/main.css
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,20 @@ main {
font-size: 1.25rem;
}

#mobile-header-logo {
height: 2rem;
width: 2rem;
}

#sidebar-title {
color: inherit;
text-decoration: none;
font-weight: 500;
font-size: 1.5rem;
line-height: 1;
}

#sidebar-logo {
height: 2.5rem;
width: 2.5rem;
}
190 changes: 87 additions & 103 deletions src/commands/build/assets/template.html
Original file line number Diff line number Diff line change
@@ -1,125 +1,109 @@
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<meta name="generator" content="custom" />
<title>{{.Title}}</title>
<meta name="description" content="{{.Description}}" />

<meta name="twitter:card" content="summary" />
{{if ne .Twitter ""}}
<meta name="twitter:site" content="{{.Twitter}}" />
{{end}}
<meta name="twitter:title" content="{{.Title}}" />
<meta name="twitter:description" content="{{.Description}}" />
<!-- <meta property="og:image" content="" /> -->
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width" />
<meta name="generator" content="custom" />
<title>{{.Title}}</title>
<meta name="description" content="{{.Description}}" />

<meta property="og:site_name" content="{{.Name}}" />
<meta property="og:title" content="{{.Title}}" />
<meta property="og:url" content="{{.Url}}" />
<meta property="og:description" content="{{.Description}}" />
<meta name="twitter:card" content="summary" />
{{if ne .Twitter ""}}
<meta name="twitter:site" content="{{.Twitter}}" />
{{end}}
<meta name="twitter:title" content="{{.Title}}" />
<meta name="twitter:description" content="{{.Description}}" />

<link rel="stylesheet" href="/main.css" />
<link rel="stylesheet" href="/markdown.css" />
</head>
<body>
<div id="mobile-top">
<div id="mobile-top-container">
<header id="mobile-header">
<a href="/" id="mobile-header-title">{{.Name}}</a>
<button
id="toggle-mobile-menu-button"
class="h-8 w-8 rounded p-2 lg:hidden"
aria-label="Toggle menu"
>
<svg
id="toggle-mobile-menu-button-menu-icon"
aria-hidden="true"
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 17 14"
>
<path
stroke="#2c2c2c"
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
d="M1 1h15M1 7h15M1 13h15"
></path>
</svg>
<svg
id="toggle-mobile-menu-button-close-icon"
class="hidden"
aria-hidden="true"
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 14 14"
>
<path
stroke="#2c2c2c"
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
d="m1 1 6 6m0 0 6 6M7 7l6-6M7 7l-6 6"
></path>
</svg>
</button>
</header>
<nav id="mobile-menu-nav" class="hidden">
<meta property="og:site_name" content="{{.Name}}" />
<meta property="og:title" content="{{.Title}}" />
<meta property="og:url" content="{{.Url}}" />
<meta property="og:description" content="{{.Description}}" />
{{if ne .OGImageURL ""}}
<meta property="og:image" content="{{.OGImageURL}}" />
{{end}}

{{if .Favicon}}
<link ref="icon" href="/favicon.ico" size="any">
{{end}}

<link rel="stylesheet" href="/main.css" />
<link rel="stylesheet" href="/markdown.css" />
</head>

<body>
<div id="mobile-top">
<div id="mobile-top-container">
<header id="mobile-header">
{{if ne .LogoImageSrc ""}}
<a href="/"><img id="mobile-header-logo" src="{{.LogoImageSrc}}" /></a>
{{else}}
<a href="/" id="mobile-header-title">{{.Name}}</a>
{{end}}
<button id="toggle-mobile-menu-button" class="h-8 w-8 rounded p-2 lg:hidden" aria-label="Toggle menu">
<svg id="toggle-mobile-menu-button-menu-icon" aria-hidden="true" xmlns="http://www.w3.org/2000/svg"
fill="none" viewBox="0 0 17 14">
<path stroke="#2c2c2c" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
d="M1 1h15M1 7h15M1 13h15"></path>
</svg>
<svg id="toggle-mobile-menu-button-close-icon" class="hidden" aria-hidden="true"
xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 14 14">
<path stroke="#2c2c2c" stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
d="m1 1 6 6m0 0 6 6M7 7l6-6M7 7l-6 6"></path>
</svg>
</button>
</header>
<nav id="mobile-menu-nav" class="hidden">
{{range $section := .NavSections}}
<section>
<h2 class="nav-section-title">{{$section.Title}}</h2>
<ul class="nav-section-links-list">
{{range $page := $section.Pages}}
<li class="nav-section-links-list-item">
{{if eq $.CurrentNavPageHref $page.Href}}
<a href="{{$page.Href}}" class="current-nav-section-link">{{$page.Title}}</a>
{{else}}
<a href="{{$page.Href}}" class="nav-section-link">{{$page.Title}}</a>
{{end}}
</li>
{{end}}
</ul>
</section>
{{end}}
</nav>
</div>
</div>
<div id="content">
<div id="content-container">
<aside id="sidebar">
{{if ne .LogoImageSrc ""}}
<a href="/"><img id="sidebar-logo" src="{{.LogoImageSrc}}" /></a>
{{else}}
<a href="/" id="sidebar-title">{{.Name}}</a>
{{end}}
<nav id="sidebar-nav">
{{range $section := .NavSections}}
<section>
<h2 class="nav-section-title">{{$section.Title}}</h2>
<ul class="nav-section-links-list">
{{range $page := $section.Pages}}
<li class="nav-section-links-list-item">
{{if eq $.CurrentNavPageHref $page.Href}}
<a href="{{$page.Href}}" class="current-nav-section-link"
>{{$page.Title}}</a
>
<a href="{{$page.Href}}" class="current-nav-section-link">{{$page.Title}}</a>
{{else}}
<a href="{{$page.Href}}" class="nav-section-link"
>{{$page.Title}}</a
>
<a href="{{$page.Href}}" class="nav-section-link">{{$page.Title}}</a>
{{end}}
</li>
{{end}}
</ul>
</section>
{{end}}
</nav>
</div>
</aside>
<main>{{.Markdown}}</main>
</div>
<div id="content">
<div id="content-container">
<aside id="sidebar">
<a href="/" id="sidebar-title">{{.Name}}</a>
<nav id="sidebar-nav">
{{range $section := .NavSections}}
<section>
<h2 class="nav-section-title">{{$section.Title}}</h2>
<ul class="nav-section-links-list">
{{range $page := $section.Pages}}
<li class="nav-section-links-list-item">
{{if eq $.CurrentNavPageHref $page.Href}}
<a href="{{$page.Href}}" class="current-nav-section-link"
>{{$page.Title}}</a
>
{{else}}
<a href="{{$page.Href}}" class="nav-section-link"
>{{$page.Title}}</a
>
{{end}}
</li>
{{end}}
</ul>
</section>
{{end}}
</nav>
</aside>
<main>{{.Markdown}}</main>
</div>
</div>
</body>
</div>
</body>

</html>

<script>
Expand All @@ -145,4 +129,4 @@ <h2 class="nav-section-title">{{$section.Title}}</h2>
.classList.remove("hidden");
}
});
</script>
</script>
26 changes: 17 additions & 9 deletions src/commands/build/code-block-links.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,14 @@ func (a codeBlockLinksAstTransformer) Transform(node *ast.Document, reader text.
defCount := 0
for i := 0; i < lineCount; i++ {
lineValue := string(reader.Value(n.Lines().At(i)))
if !strings.HasPrefix(lineValue, "//$") {
break
if strings.HasPrefix(lineValue, "//$") {
defCount += 1
keyValue := strings.Split(strings.TrimSpace(strings.Replace(lineValue, "//$", "", 1)), "=")
if len(keyValue) != 2 {
continue
}
n.SetAttribute([]byte("link:"+keyValue[0]), keyValue[1])
}
defCount += 1
keyValue := strings.Split(strings.TrimSpace(strings.Replace(lineValue, "//$", "", 1)), "=")
if len(keyValue) != 2 {
continue
}
n.SetAttribute([]byte("link:"+keyValue[0]), keyValue[1])
}
n.Lines().SetSliced(defCount, n.Lines().Len())
return ast.WalkContinue, nil
Expand All @@ -64,6 +63,15 @@ func (r codeBlockLinksRenderer) renderCustomCodeBlockLinks(w util.BufWriter, sou
line := codeBlock.Lines().At(i)
content += string(line.Value(source))
}
for _, attribute := range node.Attributes() {
attributeName := string(attribute.Name)
if !strings.HasPrefix(attributeName, "link:") {
continue
}
target := strings.Replace(attributeName, "link:", "", 1)
content = strings.ReplaceAll(content, "$$"+target, "__MALTA_CODEBLOCK_LINK_"+target)

}
lexer := lexers.Get(string(codeBlock.Language(source)))
if lexer == nil {
w.WriteString("<pre class=\"codeblock\"><code>")
Expand Down Expand Up @@ -91,7 +99,7 @@ func (r codeBlockLinksRenderer) renderCustomCodeBlockLinks(w util.BufWriter, sou
}
target := strings.Replace(attributeName, "link:", "", 1)
dest := attribute.Value.(string)
html = strings.ReplaceAll(html, "$$"+target, fmt.Sprintf("<a href=\"%s\">%s</a>", dest, target))
html = strings.ReplaceAll(html, "__MALTA_CODEBLOCK_LINK_"+target, fmt.Sprintf("<a href=\"%s\">%s</a>", dest, target))
}

w.WriteString("<pre class=\"codeblock\"><code>")
Expand Down

0 comments on commit a32af84

Please sign in to comment.