Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
Org Flux
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Stephen D
Org Flux
Commits
dca27bd5
Commit
dca27bd5
authored
2 years ago
by
Stephen D
Browse files
Options
Downloads
Patches
Plain Diff
stop hardcoding logo
parent
fd8c9a8d
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
src/blog.rs
+49
-44
49 additions, 44 deletions
src/blog.rs
src/config.rs
+9
-0
9 additions, 0 deletions
src/config.rs
src/image.rs
+1
-0
1 addition, 0 deletions
src/image.rs
src/main.rs
+9
-5
9 additions, 5 deletions
src/main.rs
src/misc.rs
+1
-0
1 addition, 0 deletions
src/misc.rs
with
69 additions
and
49 deletions
src/blog.rs
+
49
−
44
View file @
dca27bd5
...
...
@@ -5,8 +5,8 @@ use fnv::FnvHashMap;
use
warp
::
hyper
::
StatusCode
;
use
crate
::{
favicon
::
Favicon
,
image
::
MyImage
,
load
::
load_from_path
,
misc
::
Misc
,
path
::
UrlPath
,
post
::
Post
,
resp
::
Response
,
style
::
Style
,
config
::
Logo
,
favicon
::
Favicon
,
image
::
MyImage
,
load
::
load_from_path
,
misc
::
Misc
,
path
::
UrlPath
,
post
::
Post
,
resp
::
Response
,
style
::
Style
,
};
pub
struct
Blog
{
...
...
@@ -19,10 +19,16 @@ pub struct Blog {
misc
:
Vec
<
Misc
>
,
custom_style
:
Option
<
Style
>
,
favicon
:
Option
<
Favicon
>
,
logo
:
Option
<
Logo
>
,
}
impl
Blog
{
pub
fn
new
(
name
:
String
,
description
:
String
,
base_path
:
&
Path
)
->
Result
<
Self
,
Error
>
{
pub
fn
new
(
name
:
String
,
description
:
String
,
base_path
:
&
Path
,
logo
:
Option
<
Logo
>
,
)
->
Result
<
Self
,
Error
>
{
let
pages
=
load_from_path
(
base_path
,
&
base_path
.join
(
"pages"
),
"pages"
)
?
;
let
posts
=
load_from_path
(
base_path
,
&
base_path
.join
(
"posts"
),
"posts"
)
?
;
let
imgs
=
load_from_path
(
base_path
,
&
base_path
.join
(
"assets/img"
),
""
)
?
;
...
...
@@ -39,6 +45,7 @@ impl Blog {
misc
,
custom_style
,
favicon
,
logo
,
})
}
...
...
@@ -56,7 +63,36 @@ impl Blog {
content
.push_str
(
"</table>"
);
Ok
(
dress_page
(
name
,
None
,
&
content
,
&
self
.pages
,
&
self
.favicon
))
Ok
(
self
.dress_page
(
None
,
&
content
))
}
fn
dress_page
(
&
self
,
title
:
Option
<&
str
>
,
content
:
&
str
)
->
String
{
let
title
=
match
title
{
Some
(
title
)
=>
format!
(
"{} | {}"
,
title
.trim
(),
self
.name
.trim
()),
None
=>
self
.name
.trim
()
.to_string
(),
};
let
favicons
=
match
&
self
.favicon
{
Some
(
f
)
=>
f
.html
(),
None
=>
""
,
};
let
logo
=
match
&
self
.logo
{
Some
(
logo
)
=>
format!
(
r#"<img src="{}" width="{}" height="{}" alt="{}" class="align-right" />"#
,
logo
.path
,
logo
.width
,
logo
.height
,
logo
.alt
),
None
=>
""
.to_string
(),
};
let
mut
page_links
=
String
::
new
();
for
p
in
&
self
.pages
{
page_links
.push_str
(
&
p
.link_short
());
}
format!
(
r#"<!DOCTYPE html><html lang="en"><head><meta name="viewport" content="width=device-width, initial-scale=1"><link rel="stylesheet" href="/style.css" />{favicons}<title>{title}</title></head><body><div><a href="/">Home</a>{page_links}{logo}</div><hr>{content}</body></html>"#
)
}
}
...
...
@@ -84,13 +120,13 @@ impl TryFrom<Blog> for RenderedBlog {
let
mut
pages
=
FnvHashMap
::
default
();
for
p
in
&
b
.posts
{
let
body
=
dress_page
(
&
b
.name
,
Some
(
&
p
.title
),
&
p
.html
()
?
,
&
b
.pages
,
&
b
.favicon
);
let
body
=
b
.
dress_page
(
Some
(
&
p
.title
),
&
p
.html
()
?
);
insert_path
(
&
mut
pages
,
&
p
.url
,
Response
::
html
(
body
))
?
;
}
for
p
in
&
b
.pages
{
let
body
=
dress_page
(
&
b
.name
,
Some
(
&
p
.title
),
&
p
.html
()
?
,
&
b
.pages
,
&
b
.favicon
);
let
body
=
b
.
dress_page
(
Some
(
&
p
.title
),
&
p
.html
()
?
);
insert_path
(
&
mut
pages
,
&
p
.url
,
Response
::
html
(
body
))
?
;
}
...
...
@@ -105,23 +141,19 @@ impl TryFrom<Blog> for RenderedBlog {
let
home
=
b
.home
()
?
;
insert_path
(
&
mut
pages
,
"/"
,
Response
::
html
(
home
))
?
;
for
img
in
b
.imgs
{
let
(
original_url
,
original
,
thumbnail_url
,
thumbnail
)
=
img
.into_responses
()
?
;
for
img
in
&
b
.imgs
{
let
(
original_url
,
original
,
thumbnail_url
,
thumbnail
)
=
img
.clone
()
.into_responses
()
?
;
insert_path
(
&
mut
pages
,
&
thumbnail_url
,
thumbnail
)
?
;
insert_path
(
&
mut
pages
,
&
original_url
,
original
)
?
;
}
for
m
in
b
.misc
{
insert_path
(
&
mut
pages
,
&
m
.url
.clone
(),
m
.response
())
?
;
for
m
in
&
b
.misc
{
insert_path
(
&
mut
pages
,
&
m
.url
.clone
(),
m
.
clone
()
.
response
())
?
;
}
let
not_found
=
Response
::
html
(
dress_page
(
&
b
.name
,
Some
(
"Page not found"
),
include_str!
(
"assets/404.html"
),
&
b
.pages
,
&
b
.favicon
,
));
let
not_found
=
Response
::
html
(
b
.dress_page
(
Some
(
"Page not found"
),
include_str!
(
"assets/404.html"
)));
if
let
Some
(
fav
)
=
b
.favicon
{
for
(
p
,
r
)
in
fav
.responses
{
...
...
@@ -152,30 +184,3 @@ fn insert_path(
Ok
(())
}
fn
dress_page
(
site_name
:
&
str
,
title
:
Option
<&
str
>
,
content
:
&
str
,
pages
:
&
[
Post
],
favicon
:
&
Option
<
Favicon
>
,
)
->
String
{
let
title
=
match
title
{
Some
(
title
)
=>
format!
(
"{} | {}"
,
title
.trim
(),
site_name
.trim
()),
None
=>
site_name
.trim
()
.to_string
(),
};
let
favicons
=
match
favicon
{
Some
(
f
)
=>
f
.html
(),
None
=>
""
,
};
let
mut
page_links
=
String
::
new
();
for
p
in
pages
{
page_links
.push_str
(
&
p
.link_short
());
}
format!
(
r#"<!DOCTYPE html><html lang="en"><head><meta name="viewport" content="width=device-width, initial-scale=1"><link rel="stylesheet" href="/style.css" />{favicons}<title>{title}</title></head><body><div><a href="/">Home</a>{page_links}<img src="/img/logo.png" class="align-right" /></div><hr>{content}</body></html>"#
)
}
This diff is collapsed.
Click to expand it.
src/config.rs
+
9
−
0
View file @
dca27bd5
...
...
@@ -3,11 +3,20 @@ use std::fs;
use
anyhow
::
anyhow
;
use
serde
::
Deserialize
;
#[derive(Deserialize)]
pub
struct
Logo
{
pub
path
:
String
,
pub
width
:
String
,
pub
height
:
String
,
pub
alt
:
String
,
}
#[derive(Deserialize)]
pub
struct
Config
{
pub
name
:
String
,
pub
description
:
String
,
pub
path
:
String
,
pub
logo
:
Option
<
Logo
>
,
}
impl
Config
{
...
...
This diff is collapsed.
Click to expand it.
src/image.rs
+
1
−
0
View file @
dca27bd5
...
...
@@ -9,6 +9,7 @@ use crate::{
util
::
slugify
,
};
#[derive(Clone)]
pub
struct
MyImage
{
original
:
DynamicImage
,
thumbnail
:
DynamicImage
,
...
...
This diff is collapsed.
Click to expand it.
src/main.rs
+
9
−
5
View file @
dca27bd5
...
...
@@ -53,11 +53,15 @@ async fn handle_request(
async
fn
main
()
{
let
config
=
Config
::
load
()
.unwrap
();
let
blog
:
RenderedBlog
=
Blog
::
new
(
config
.name
,
config
.description
,
&
PathBuf
::
from
(
config
.path
))
.unwrap
()
.try_into
()
.unwrap
();
let
blog
:
RenderedBlog
=
Blog
::
new
(
config
.name
,
config
.description
,
&
PathBuf
::
from
(
config
.path
),
config
.logo
,
)
.unwrap
()
.try_into
()
.unwrap
();
let
blog
=
Arc
::
new
(
RwLock
::
new
(
blog
));
let
blog_filter
=
warp
::
any
()
.map
(
move
||
blog
.clone
());
...
...
This diff is collapsed.
Click to expand it.
src/misc.rs
+
1
−
0
View file @
dca27bd5
...
...
@@ -8,6 +8,7 @@ use crate::{
util
::
slugify
,
};
#[derive(Clone)]
pub
struct
Misc
{
pub
url
:
String
,
content_type
:
&
'static
str
,
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment