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
3ad00b0b
Commit
3ad00b0b
authored
2 years ago
by
Stephen D
Browse files
Options
Downloads
Patches
Plain Diff
content-type fixes
parent
07849872
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/blog.rs
+2
-2
2 additions, 2 deletions
src/blog.rs
src/misc.rs
+18
-2
18 additions, 2 deletions
src/misc.rs
src/resp.rs
+7
-0
7 additions, 0 deletions
src/resp.rs
with
27 additions
and
4 deletions
src/blog.rs
+
2
−
2
View file @
3ad00b0b
...
...
@@ -68,7 +68,7 @@ impl TryFrom<Blog> for RenderedBlog {
pages
.insert
(
"/style.css"
.to_string
(),
Response
::
html
(
include_str!
(
"assets/style.css"
)
.to_string
()),
Response
::
css
(
include_str!
(
"assets/style.css"
)
.to_string
()),
);
let
home
=
b
.home
()
?
;
...
...
@@ -97,6 +97,6 @@ impl TryFrom<Blog> for RenderedBlog {
fn
dress_page
(
title
:
&
str
,
content
:
&
str
)
->
String
{
format!
(
r#"<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><hr>{content}</body></html>"#
)
}
This diff is collapsed.
Click to expand it.
src/misc.rs
+
18
−
2
View file @
3ad00b0b
use
std
::{
fs
::
File
,
io
::
Read
};
use
anyhow
::
Context
;
use
anyhow
::
{
bail
,
Context
}
;
use
crate
::{
load
::
Loadable
,
resp
::
Response
,
util
::
slugify
};
...
...
@@ -19,6 +19,12 @@ impl Loadable for Misc {
.context
(
"Could not convert filename into string"
)
?
.to_owned
();
let
extension
=
path
.extension
()
.with_context
(||
format!
(
"Could not get extension for {file_name}"
))
?
.to_str
()
.context
(
"Extension could not be converted to a string"
)
?
;
let
url
=
slugify
(
&
format!
(
"/{slug_prefix}/{file_name}"
));
let
mut
data
=
vec!
[];
...
...
@@ -26,7 +32,7 @@ impl Loadable for Misc {
Ok
(
Self
{
data
,
content_type
:
"todo"
,
content_type
:
content_type
(
extension
)
?
,
url
,
})
}
...
...
@@ -40,3 +46,13 @@ impl Misc {
}
}
}
fn
content_type
(
ext
:
&
str
)
->
anyhow
::
Result
<&
'static
str
>
{
let
c
=
match
ext
{
"webm"
=>
"video/webm"
,
"mp4"
=>
"video/mp4"
,
_
=>
bail!
(
"Unsure how to handle extension {ext}"
),
};
Ok
(
c
)
}
This diff is collapsed.
Click to expand it.
src/resp.rs
+
7
−
0
View file @
3ad00b0b
...
...
@@ -11,4 +11,11 @@ impl Response {
data
:
html
.into_bytes
(),
}
}
pub
fn
css
(
css
:
String
)
->
Self
{
Self
{
content_type
:
"text/css; charset=utf-8"
,
data
:
css
.into_bytes
(),
}
}
}
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