Skip to content

Commit

Permalink
feat: dark theme to add
Browse files Browse the repository at this point in the history
  • Loading branch information
dd84ai committed Feb 3, 2024
1 parent ebf5718 commit 5a09952
Show file tree
Hide file tree
Showing 21 changed files with 162 additions and 78 deletions.
14 changes: 7 additions & 7 deletions blog/about/about.templ
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ package about

import (
"darklab_blog/blog/common"
"darklab_blog/blog/common/types"
"darklab_blog/blog/about/about_static"
"darklab_blog/blog/settings"
)

templ Intro() {
templ Intro(gp types.GlobalParams) {
@common.TextHeaderMain(){
Intro
}
<img class="myphoto" src={ settings.StaticRoot + "about/myphoto.png" } alt="my photo"/>
<img class="myphoto" src={ gp.StaticRoot + "about/myphoto.png" } alt="my photo"/>
@common.TextBlock(){
Hi there! My name is Andrei Novoselov.
}
Expand Down Expand Up @@ -54,15 +54,15 @@ templ Contacts() {
}
}

templ AboutT() {
@common.Html5(common.Title("About")) {
templ AboutT(gp types.GlobalParams) {
@common.Html5(gp,common.Title("About")) {
@common.BlogFrame() {
@about_static.AboutCSS()
@common.Menu()
@common.Menu(gp)
@common.PageHeader(){
About
}
@Intro()
@Intro(gp)
<hr/>
@Contacts()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package article_git_conventional_commits

import (
"darklab_blog/blog/common/markdowner"
"darklab_blog/blog/common/types"
"darklab_blog/blog/pet_projects/pet_projects_urls"
"darklab_blog/blog/settings"
"strings"
"time"

Expand All @@ -16,14 +16,14 @@ type Vars struct {
AutogitURL string
}

func init() {
Body = markdowner.ReadMarkdownAndTemplate(
func GetBody(gp types.GlobalParams) string {
return string(markdowner.ReadMarkdownAndTemplate(
utils_filepath.Join(utils.GetCurrentFolder(), "git_conv_commits.md"),
Vars{
StaticRoot: settings.StaticRoot,
StaticRoot: gp.StaticRoot,
AutogitURL: pet_projects_urls.Autogit,
},
)
))
}

var (
Expand All @@ -33,5 +33,4 @@ var (
Software development is a team effort, and therefore it requires communicating
what we change and why we change it.`, "\n", "")
Date = time.Date(2023, time.December, 11, 0, 0, 0, 0, time.UTC)
Body []byte
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@ package article_git_conventional_commits

import (
"darklab_blog/blog/common"
"darklab_blog/blog/common/types"
)

templ ArticleT() {
@common.Html5(common.Title("Git conventional commit")) {
templ ArticleT(gp types.GlobalParams) {
@common.Html5(gp,common.Title("Git conventional commit")) {
@common.BlogFrame() {
<style>
img {
max-width: 800px;
}
</style>
@common.Menu()
@templ.Raw(string(Body))
@common.Menu(gp)
@templ.Raw(GetBody(gp))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package article_static_typed_logging

import (
"darklab_blog/blog/common/markdowner"
"darklab_blog/blog/common/types"
"darklab_blog/blog/pet_projects/pet_projects_urls"
"darklab_blog/blog/settings"
"strings"
"time"

Expand All @@ -17,21 +17,20 @@ type Vars struct {
PyTypelog string
}

func init() {
Body = markdowner.ReadMarkdownAndTemplate(
func GetBody(gp types.GlobalParams) string {
return string(markdowner.ReadMarkdownAndTemplate(
utils_filepath.Join(utils.GetCurrentFolder(), "typelog.md"),
Vars{
StaticRoot: settings.StaticRoot,
StaticRoot: gp.StaticRoot,
GoTypelog: pet_projects_urls.GoTypelog,
PyTypelog: pet_projects_urls.PyTypelog,
},
)
))
}

var (
Headline = "Typelog - type safe structured logging"
Intro = strings.ReplaceAll(`With modern logging systems able to parse JSON out of the box, we need defining easily jsonable logs.
Known solutions do not do it consistently and in a type safe way. Typelog comes to rescue.`, "\n", "")
Date = time.Date(2024, time.January, 28, 0, 0, 0, 0, time.UTC)
Body []byte
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@ package article_static_typed_logging

import (
"darklab_blog/blog/common"
"darklab_blog/blog/common/types"
)

templ ArticleT() {
@common.Html5(common.Title("Typelog - type safe structured logging")) {
templ ArticleT(gp types.GlobalParams) {
@common.Html5(gp,common.Title("Typelog - type safe structured logging")) {
@common.BlogFrame() {
<style>
img {
max-width: 800px;
}
</style>
@common.Menu()
@templ.Raw(string(Body))
@common.Menu(gp)
@templ.Raw(GetBody(gp))
}
}
}
7 changes: 4 additions & 3 deletions blog/articles/articles.templ
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package articles

import (
"darklab_blog/blog/common"
"darklab_blog/blog/common/types"
"darklab_blog/blog/common/urls"
"darklab_blog/blog/articles/article_detailed/article_git_conventional_commits"
"darklab_blog/blog/articles/article_detailed/article_static_typed_logging"
Expand Down Expand Up @@ -37,11 +38,11 @@ templ HomeBody() {
)
}

templ HomeT() {
@common.Html5(common.Title("Articles")) {
templ HomeT(gp types.GlobalParams) {
@common.Html5(gp,common.Title("Articles")) {
@article_static.ArticleCSS()
@common.BlogFrame() {
@common.Menu()
@common.Menu(gp)
@HomeBody()
}
}
Expand Down
49 changes: 39 additions & 10 deletions blog/common/builder/builder.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package builder

import (
"darklab_blog/blog/common/types"
"darklab_blog/blog/settings"
"os"

Expand All @@ -10,36 +11,64 @@ import (
"github.com/darklab8/darklab_goutils/goutils/utils/utils_types"
)

const BuildpathDefault utils_types.FilePath = "build"

type Builder struct {
components []*Component
build_path utils_types.FilePath
}

func NewBuilder() *Builder {
return &Builder{}
type BuilderOption func(b *Builder)

func NewBuilder(opts ...BuilderOption) *Builder {
b := &Builder{}
for _, opt := range opts {
opt(b)
}
return b
}

func (b *Builder) RegComps(components ...*Component) {
b.components = append(b.components, components...)
}

func (b *Builder) build(buildpath utils_types.FilePath) {
os.RemoveAll(buildpath.ToString())
os.MkdirAll(buildpath.ToString(), os.ModePerm)
func (b *Builder) build(params types.GlobalParams) {
os.RemoveAll(params.Buildpath.ToString())
os.MkdirAll(params.Buildpath.ToString(), os.ModePerm)

for _, comp := range b.components {
comp.Write(buildpath)
comp.Write(params)
}

folders := utils_os.GetRecursiveDirs(settings.ProjectFolder)
for _, folder := range folders {
if utils_filepath.Base(folder) == "static" {
utils_cp.Dir(folder.ToString(), utils_filepath.Join(settings.ProjectFolder, utils_types.FilePath(buildpath.ToString()), "static").ToString())
utils_cp.Dir(folder.ToString(),
utils_filepath.Join(settings.ProjectFolder, utils_types.FilePath(params.Buildpath.ToString()), "static").ToString())
}
}
}

func (b *Builder) BuildAll() {
b.build(BuildpathDefault)
staticPrefix := "static/"

var siteRoot string
if value, ok := os.LookupEnv("SITE_ROOT"); ok {
siteRoot = value
} else {
siteRoot = "/"
}
b.build(types.GlobalParams{
Buildpath: "build",
Theme: types.ThemeDark,
SiteRoot: siteRoot,
StaticRoot: siteRoot + staticPrefix,
OppositeThemeRoot: siteRoot + "light/",
})
b.build(types.GlobalParams{
Buildpath: "build/light",
Theme: types.ThemeLight,
SiteRoot: siteRoot + "light/",
StaticRoot: siteRoot + "light/" + staticPrefix,
OppositeThemeRoot: siteRoot,
})

}
11 changes: 6 additions & 5 deletions blog/common/builder/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package builder
import (
"bytes"
"context"
"darklab_blog/blog/common/types"
"darklab_blog/blog/settings"
"darklab_blog/blog/settings/logus"
"os"
Expand All @@ -17,25 +18,25 @@ import (

type Component struct {
relpath utils_types.FilePath
templ_comp templ.Component
templ_comp func(gp types.GlobalParams) templ.Component
}

func NewComponent(
relpath utils_types.FilePath,
templ_comp templ.Component,
templ_comp func(gp types.GlobalParams) templ.Component,
) *Component {
return &Component{
relpath: relpath,
templ_comp: templ_comp,
}
}

func (h *Component) Write(buildpath utils_types.FilePath) {
func (h *Component) Write(gp types.GlobalParams) {
buf := bytes.NewBuffer([]byte{})

h.templ_comp.Render(context.Background(), buf)
h.templ_comp(gp).Render(context.Background(), buf)

abs_buildpath := utils_filepath.Join(settings.ProjectFolder, buildpath, h.relpath)
abs_buildpath := utils_filepath.Join(settings.ProjectFolder, gp.Buildpath, h.relpath)
haveParentFoldersCreated(abs_buildpath)

err := os.WriteFile(abs_buildpath.ToString(), gohtml.FormatBytes(buf.Bytes()), os.ModePerm)
Expand Down
1 change: 0 additions & 1 deletion blog/common/common_static/common.templ
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ templ CommonCSS() {
margin-left: 15px;
list-style-type: circle;
list-style-position: inside;
color: black;
}
</style>
}
2 changes: 1 addition & 1 deletion blog/common/common_static/custom.templ
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package common_static


templ CustomCSS() {
<style data-custom-css>
:root {
--color_hover_link: #4183C4;
--color_link: #33618E;
/* color: var(--blue); how to apply*/
}

/*My custom stuff*/

.blog_space {
Expand Down
10 changes: 5 additions & 5 deletions blog/common/menu.templ
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package common

import (
"darklab_blog/blog/settings"
"darklab_blog/blog/common/urls"
"darklab_blog/blog/common/types"
)

templ NavElem(url string) {
Expand All @@ -11,15 +11,15 @@ templ NavElem(url string) {
</div></a>
}

templ Menu() {
templ Menu(gp types.GlobalParams) {
<menu class="main_menu">
@NavElem(settings.SiteRoot) {
@NavElem(gp.SiteRoot) {
Articles
}
@NavElem(settings.SiteRoot + urls.PetProjects) {
@NavElem(gp.SiteRoot + urls.PetProjects) {
Pet projects
}
@NavElem(settings.SiteRoot + urls.About) {
@NavElem(gp.SiteRoot + urls.About) {
About
}
</menu>
Expand Down
Loading

0 comments on commit 5a09952

Please sign in to comment.