Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
org-static
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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Stephen D
org-static
Commits
1a41ded7
Commit
1a41ded7
authored
Feb 9, 2023
by
Stephen D
Browse files
Options
Downloads
Patches
Plain Diff
page support
parent
c8bf7385
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/assets/style.css
+4
-0
4 additions, 0 deletions
src/assets/style.css
src/blog.rs
+19
-12
19 additions, 12 deletions
src/blog.rs
src/post.rs
+38
-16
38 additions, 16 deletions
src/post.rs
with
61 additions
and
28 deletions
src/assets/style.css
+
4
−
0
View file @
1a41ded7
...
...
@@ -54,3 +54,7 @@ img, video {
th
,
td
{
padding-left
:
1em
;
}
.page-link
{
padding-left
:
1em
;
}
This diff is collapsed.
Click to expand it.
src/blog.rs
+
19
−
12
View file @
1a41ded7
...
...
@@ -7,7 +7,7 @@ use crate::{
};
pub
struct
Blog
{
//
pages: Vec<P
age
>,
pages
:
Vec
<
P
ost
>
,
posts
:
Vec
<
Post
>
,
imgs
:
Vec
<
MyImage
>
,
misc
:
Vec
<
Misc
>
,
...
...
@@ -16,19 +16,14 @@ pub struct Blog {
impl
Blog
{
pub
fn
new
()
->
Result
<
Self
,
Error
>
{
/*let pages = fs::read_dir("pages")?
.map(|path| Page::new(path?)?)
.collect();*/
let
pages
=
load_from_path
(
"pages"
,
"pages"
)
?
;
let
posts
=
load_from_path
(
"posts"
,
"posts"
)
?
;
let
imgs
=
load_from_path
(
"assets/img"
,
""
)
?
;
let
misc
=
load_from_path
(
"assets/misc"
,
"misc"
)
?
;
let
custom_style
=
Style
::
load_if_exists
(
"assets/style.css"
)
?
;
Ok
(
Self
{
pages
,
posts
,
imgs
,
misc
,
...
...
@@ -50,7 +45,7 @@ impl Blog {
content
.push_str
(
"</table>"
);
Ok
(
dress_page
(
"Stephen's Site"
,
&
content
))
Ok
(
dress_page
(
"Stephen's Site"
,
&
content
,
&
self
.pages
))
}
}
...
...
@@ -75,7 +70,13 @@ impl TryFrom<Blog> for RenderedBlog {
let
mut
pages
=
HashMap
::
new
();
for
p
in
&
b
.posts
{
let
body
=
dress_page
(
&
p
.title
,
&
p
.html
()
?
);
let
body
=
dress_page
(
&
p
.title
,
&
p
.html
()
?
,
&
b
.pages
);
pages
.insert
(
p
.url
.clone
(),
Response
::
html
(
body
));
}
for
p
in
&
b
.pages
{
let
body
=
dress_page
(
&
p
.title
,
&
p
.html
()
?
,
&
b
.pages
);
pages
.insert
(
p
.url
.clone
(),
Response
::
html
(
body
));
}
...
...
@@ -103,6 +104,7 @@ impl TryFrom<Blog> for RenderedBlog {
let
not_found
=
Response
::
html
(
dress_page
(
"Page not found"
,
include_str!
(
"assets/404.html"
),
&
b
.pages
,
));
dbg!
(
pages
.keys
());
...
...
@@ -111,8 +113,13 @@ impl TryFrom<Blog> for RenderedBlog {
}
}
fn
dress_page
(
title
:
&
str
,
content
:
&
str
)
->
String
{
fn
dress_page
(
title
:
&
str
,
content
:
&
str
,
pages
:
&
[
Post
])
->
String
{
let
mut
page_links
=
String
::
new
();
for
p
in
pages
{
page_links
.push_str
(
&
p
.link_short
());
}
format!
(
r#"<!DOCTYPE html><html><head><link rel="stylesheet" href="/style.css" /><title>{title}</title></head><body><a href="/">Home</a><hr>{content}</body></html>"#
r#"<!DOCTYPE html><html><head><link rel="stylesheet" href="/style.css" /><title>{title}</title></head><body><a href="/">Home</a>
{page_links}
<hr>{content}</body></html>"#
)
}
This diff is collapsed.
Click to expand it.
src/post.rs
+
38
−
16
View file @
1a41ded7
...
...
@@ -14,7 +14,7 @@ use crate::{
#[derive(Eq)]
pub
struct
Post
{
pub
title
:
String
,
pub
date
:
Date
,
pub
date
:
Option
<
Date
>
,
pub
content
:
String
,
pub
url
:
String
,
}
...
...
@@ -24,28 +24,50 @@ impl Post {
let
title
=
&
self
.title
;
let
content
=
&
self
.content
;
let
date
=
&
self
.date_f
()
?
;
Ok
(
format!
(
r#"<div class="header-container"><h1>{title}</h1><div class="header-date">{date}</div></div>{content}"#
))
let
mut
out
=
format!
(
r#"<div class="header-container"><h1>{title}</h1>"#
);
if
let
Some
(
date
)
=
date
{
out
.push_str
(
r#"<div class="header-date">"#
);
out
.push_str
(
date
);
out
.push_str
(
"</div>"
);
}
out
.push_str
(
"</div>"
);
out
.push_str
(
content
);
Ok
(
out
)
}
pub
fn
link
(
&
self
)
->
anyhow
::
Result
<
String
>
{
let
link
=
format!
(
let
link
=
match
self
.date_f
()
?
{
Some
(
date_f
)
=>
format!
(
r#"<tr><td><a href="{}">{}</a></td><td>[{}]</td></tr>"#
,
self
.url
,
self
.title
,
self
.date_f
()
?
);
self
.url
,
self
.title
,
date_f
),
None
=>
format!
(
r#"<tr><td><a href="{}">{}</a></td><td></td></tr>"#
,
self
.url
,
self
.title
),
};
Ok
(
link
)
}
fn
date_f
(
&
self
)
->
anyhow
::
Result
<
String
>
{
let
date_f
=
self
.date
.format
(
format_description!
(
"[day] [month repr:short] [year]"
))
?
;
pub
fn
link_short
(
&
self
)
->
String
{
format!
(
r#"<a href="{}" class="page-link">{}</a>"#
,
self
.url
,
self
.title
)
}
fn
date_f
(
&
self
)
->
anyhow
::
Result
<
Option
<
String
>>
{
let
date_f
=
match
self
.date
{
Some
(
date
)
=>
date
.format
(
format_description!
(
"[day] [month repr:short] [year]"
))
?
,
None
=>
return
Ok
(
None
),
};
Ok
(
date_f
)
Ok
(
Some
(
date_f
)
)
}
}
...
...
@@ -137,7 +159,7 @@ impl Parser<Post> for PostParser {
fn
render
(
self
)
->
anyhow
::
Result
<
Post
>
{
let
title
=
self
.title
.context
(
"Could not find post title"
)
?
;
let
date
=
self
.date
.context
(
"Could not find post date"
)
?
;
let
date
=
self
.date
;
let
content
=
String
::
from_utf8
(
self
.content
)
?
;
let
url
=
self
.url
;
...
...
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
sign in
to comment