💾 Archived View for lists.flounder.online › patches › threads › 20210317214420.11511-2-johann@qwertq… captured on 2022-07-16 at 16:25:28. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2022-04-28)

-=-=-=-=-=-=-

[PATCH mygit 2/2] handle repos without readme

[PATCH mygit 2/2] handle repos without readme

From: johann@qwertqwefsday.eu

Date: Wed, 17 Mar 2021 22:44:20 +0100

Message-Id: 20210317214420.11511-2-johann@qwertqwefsday.eu

To: <~aw/patches@lists.sr.ht>

In-Reply-To: 20210317214420.11511-1-johann@qwertqwefsday.eu

Cc: "Johann150" <johann@qwertqwefsday.eu>

Reply

Export

--------------------------------------

From: Johann150 <johann@qwertqwefsday.eu>

---

src/main.rs | 77 +++++++++++++++++++++++----------------------

templates/repo.html | 6 +++-

2 files changed, 45 insertions(+), 38 deletions(-)

diff --git a/src/main.rs b/src/main.rs

index 754a0c6..f11d684 100644

--- a/src/main.rs

+++ b/src/main.rs

@@ -143,44 +143,47 @@ async fn repo_home(req: Request<()>) -> tide::Result {

return Ok(RepoEmptyTemplate { repo }.into());

}

- let readme_text = {

- let mut format = ReadmeFormat::Plaintext;

- let readme = repo

- .revparse_single("HEAD:README")

- .or_else(|_| repo.revparse_single("HEAD:README.txt"))

- .or_else(|_| {

- format = ReadmeFormat::Markdown;

- repo.revparse_single("HEAD:README.md")

- })

- .or_else(|_| repo.revparse_single("HEAD:README.mdown"))

- .or_else(|_| repo.revparse_single("HEAD:README.markdown"))

- .or_else(|_| {

- format = ReadmeFormat::Html;

- repo.revparse_single("HEAD:README.html")

- })

- .or_else(|_| repo.revparse_single("HEAD:README.htm"))?;

- let readme_text = str::from_utf8(readme.as_blob().unwrap().content())?;

-

- // render the file contents to HTML

- match format {

- // render plaintext as preformatted text

- ReadmeFormat::Plaintext => {

- let mut output = "<pre>".to_string();

- escape_html(&mut output, readme_text)?;

- output.push_str("</pre>");

- output

- }

- // already is HTML

- ReadmeFormat::Html => readme_text.to_string(),

- // render Markdown to HTML

- ReadmeFormat::Markdown => {

- let mut output = String::new();

- let parser = Parser::new_ext(readme_text, Options::empty());

- push_html(&mut output, parser);

- output

+ let mut format = ReadmeFormat::Plaintext;

+ let readme_text = repo

+ .revparse_single("HEAD:README")

+ .or_else(|_| repo.revparse_single("HEAD:README.txt"))

+ .or_else(|_| {

+ format = ReadmeFormat::Markdown;

+ repo.revparse_single("HEAD:README.md")

+ })

+ .or_else(|_| repo.revparse_single("HEAD:README.mdown"))

+ .or_else(|_| repo.revparse_single("HEAD:README.markdown"))

+ .or_else(|_| {

+ format = ReadmeFormat::Html;

+ repo.revparse_single("HEAD:README.html")

+ })

+ .or_else(|_| repo.revparse_single("HEAD:README.htm"))

+ .ok()

+ .and_then(|readme| readme.into_blob().ok())

+ .map(|blob| {

+ let text = str::from_utf8(blob.content()).unwrap_or_default();

+

+ // render the file contents to HTML

+ match format {

+ // render plaintext as preformatted text

+ ReadmeFormat::Plaintext => {

+ let mut output = "<pre>".to_string();

+ escape_html(&mut output, text).unwrap();

+ output.push_str("</pre>");

+ output

+ }

+ // already is HTML

+ ReadmeFormat::Html => text.to_string(),

+ // render Markdown to HTML

+ ReadmeFormat::Markdown => {

+ let mut output = String::new();

+ let parser = Parser::new_ext(text, Options::empty());

+ push_html(&mut output, parser);

+ output

+ }

}

- }

- };

+ })

+ .unwrap_or_default();

Ok(RepoHomeTemplate { repo, readme_text }.into())

}

diff --git a/templates/repo.html b/templates/repo.html

index e2fcd0e..5598325 100644

--- a/templates/repo.html

+++ b/templates/repo.html

@@ -2,5 +2,9 @@

{% block content %}

{% include "repo-navbar.html" %}

- {{ readme_text|safe }}

+ {% if !readme_text.is_empty() -%}

+ {{ readme_text|safe }}

+ {% else -%}

+ <em>(no README)</em>

+ {%- endif %}

{% endblock %}

--

2.20.1

Re: [PATCH mygit 2/2] handle repos without readme

From: alex@alexwennerberg.com

Date: Wed, 17 Mar 2021 17:07:20 -0700

Message-Id: CA01F67XP8O2.1ANJSDV1CZMTU@debian-alex

To: "Johann Galle" <johann@qwertqwefsday.eu>, <~aw/patches@lists.sr.ht>

In-Reply-To: 20210317214420.11511-2-johann@qwertqwefsday.eu

Reply

Export

--------------------------------------

Applied, thank you! We're making some good progress -- I might be able

to dedicate a full day this weekend to getting an Alpha working

On Wed Mar 17, 2021 at 2:44 PM PDT, Johann Galle wrote:

From: Johann150 <johann@qwertqwefsday.eu>
---
src/main.rs | 77 +++++++++++++++++++++++----------------------
templates/repo.html | 6 +++-
2 files changed, 45 insertions(+), 38 deletions(-)
diff --git a/src/main.rs b/src/main.rs
index 754a0c6..f11d684 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -143,44 +143,47 @@ async fn repo_home(req: Request<()>) ->
tide::Result {
return Ok(RepoEmptyTemplate { repo }.into());
}
- let readme_text = {
- let mut format = ReadmeFormat::Plaintext;
- let readme = repo
- .revparse_single("HEAD:README")
- .or_else(|_| repo.revparse_single("HEAD:README.txt"))
- .or_else(|_| {
- format = ReadmeFormat::Markdown;
- repo.revparse_single("HEAD:README.md")
- })
- .or_else(|_| repo.revparse_single("HEAD:README.mdown"))
- .or_else(|_| repo.revparse_single("HEAD:README.markdown"))
- .or_else(|_| {
- format = ReadmeFormat::Html;
- repo.revparse_single("HEAD:README.html")
- })
- .or_else(|_| repo.revparse_single("HEAD:README.htm"))?;
- let readme_text =
str::from_utf8(readme.as_blob().unwrap().content())?;
-
- // render the file contents to HTML
- match format {
- // render plaintext as preformatted text
- ReadmeFormat::Plaintext => {
- let mut output = "<pre>".to_string();
- escape_html(&mut output, readme_text)?;
- output.push_str("</pre>");
- output
- }
- // already is HTML
- ReadmeFormat::Html => readme_text.to_string(),
- // render Markdown to HTML
- ReadmeFormat::Markdown => {
- let mut output = String::new();
- let parser = Parser::new_ext(readme_text, Options::empty());
- push_html(&mut output, parser);
- output
+ let mut format = ReadmeFormat::Plaintext;
+ let readme_text = repo
+ .revparse_single("HEAD:README")
+ .or_else(|_| repo.revparse_single("HEAD:README.txt"))
+ .or_else(|_| {
+ format = ReadmeFormat::Markdown;
+ repo.revparse_single("HEAD:README.md")
+ })
+ .or_else(|_| repo.revparse_single("HEAD:README.mdown"))
+ .or_else(|_| repo.revparse_single("HEAD:README.markdown"))
+ .or_else(|_| {
+ format = ReadmeFormat::Html;
+ repo.revparse_single("HEAD:README.html")
+ })
+ .or_else(|_| repo.revparse_single("HEAD:README.htm"))
+ .ok()
+ .and_then(|readme| readme.into_blob().ok())
+ .map(|blob| {
+ let text = str::from_utf8(blob.content()).unwrap_or_default();
+
+ // render the file contents to HTML
+ match format {
+ // render plaintext as preformatted text
+ ReadmeFormat::Plaintext => {
+ let mut output = "<pre>".to_string();
+ escape_html(&mut output, text).unwrap();
+ output.push_str("</pre>");
+ output
+ }
+ // already is HTML
+ ReadmeFormat::Html => text.to_string(),
+ // render Markdown to HTML
+ ReadmeFormat::Markdown => {
+ let mut output = String::new();
+ let parser = Parser::new_ext(text, Options::empty());
+ push_html(&mut output, parser);
+ output
+ }
}
- }
- };
+ })
+ .unwrap_or_default();
Ok(RepoHomeTemplate { repo, readme_text }.into())
}
diff --git a/templates/repo.html b/templates/repo.html
index e2fcd0e..5598325 100644
--- a/templates/repo.html
+++ b/templates/repo.html
@@ -2,5 +2,9 @@
{% block content %}
{% include "repo-navbar.html" %}
- {{ readme_text|safe }}
+ {% if !readme_text.is_empty() -%}
+ {{ readme_text|safe }}
+ {% else -%}
+ <em>(no README)</em>
+ {%- endif %}
{% endblock %}
--
2.20.1