Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v2 Markdown Testing and Feedback #2861

Closed
misfir3 opened this issue Nov 4, 2019 · 6 comments
Closed

v2 Markdown Testing and Feedback #2861

misfir3 opened this issue Nov 4, 2019 · 6 comments
Labels
feature ⚙️ New feature or request
Milestone

Comments

@misfir3
Copy link

misfir3 commented Nov 4, 2019

I have a use case, which is essentially I want to be able to write in markdown, run it across a template and serve largely static docs. Search across the markdown content is also a nice-to-have for sure. As testing/feedback/help is desired on this (https://github.com/caddyserver/caddy/wiki/v2:-Documentation#httphandlersmarkdown) ... here we go.

I have looked/am looking at Gatsby (too complex for my basic goal) and Hugo (looks good so far, also written in Go), but figured I should give Caddy a shot ... as I like its https-by-default stance and general focus on being secure and performant by default.

So, that's my basic goal/needs and why I'm looking at it ... First, I've got to make sure I get my config sane ... will comment on that next if I am unable to get there quickly and otherwise post my feedback (and links to other pertinent issues) here as I go.

@misfir3
Copy link
Author

misfir3 commented Nov 4, 2019

So, first question is ...
does v2 take any of the additional config [as does v1] (https://caddyserver.com/v1/docs/markdown)

namely ... ??

markdown [basepath] {
	ext         extensions...
	[css|js]    file
	template    [name] path
	templatedir defaultpath
}

@mholt
Copy link
Member

mholt commented Nov 4, 2019

Repasting from the previous issue (2860)...

First, have you seen the templates handler? It has a lot of functions you might find helpful: https://github.com/caddyserver/caddy/wiki/v2:-Templates -- including a .Markdown function to render markdown.

Related issues would be: #2632 and #2736

#2736 seems especially relevant. I would like to find a way to merge the two handlers, but the question is how to know whether to execute a page as markdown containing templates, or templates containing markdown?

@mholt mholt added feature ⚙️ New feature or request v2 labels Nov 4, 2019
@mholt mholt added this to the 2.0 milestone Nov 4, 2019
@mholt
Copy link
Member

mholt commented Dec 30, 2019

@misfir3 FYI, I got rid of the markdown handler and am using the templates handler for our new documentation site, which I'll be publishing in the next few days or weeks.

Basically, all URLs within /docs/ are rewritten to /docs/index.html, and each markdown file is prefixed with "front matter" (structured metadata). The templated HTML page renders it:

{{$pathParts := splitList "/" .OriginalReq.URL.Path}}
{{$markdownFilename := default "index" (slice $pathParts 2 | join "/")}}
{{$markdownFilePath := printf "/docs/markdown/%s.md" $markdownFilename}}
{{$markdownFile := (include $markdownFilePath | splitFrontMatter)}}
<!DOCTYPE html>
<html>
<head>
     <title>{{default $markdownFilename $markdownFile.Meta.title}} &mdash; Caddy Documentation</title>
    ...
    {{markdown $markdownFile.Body}}
    ...
</html>

Or something like that.

So, I will close this for now, but feel free to continue the discussion! If this isn't what you had in mind, we can continue discussing it or even reopen the issue.

@mholt mholt closed this as completed Dec 30, 2019
@casperdcl
Copy link

casperdcl commented Sep 4, 2024

FYI my approach is to handle path_regexp /.+\.md$ just before file_server browse:

domain.com {
  handle_path /some_prefix* {
    root * /www/assets

    @mdfile path_regexp /.+\.md$
    handle @mdfile {
      header Content-Type text/html
      templates {
        between "<<" ">>"
      }
      respond <<HTML
      <!DOCTYPE html>
      <html><head><title><<base .Req.URL.Path>></title></head><body>
      <a href="."><<dir .Req.URL.Path>>/</a><<base .Req.URL.Path>><hr/>
      <<readFile .Req.URL.Path | markdown>>
      </body></html>
      HTML 200
    }

    file_server browse
  }
}
  • advantages: no need for separate html template files and rewrites
  • note: replacing slice (splitList "/" .OriginalReq.URL.Path) 2 | join "/" | readFile | markdown with placeholder "re.datamd.1" | readFile | markdown doesn't work, presumably because re isn't captured despite caddyhttp: Implement placeholders in template #3324 - maybe worth opening an issue?
  • use case: file_server browse should render any markdown files nicely

casperdcl added a commit to SyneRBI/PETRIC-backend that referenced this issue Sep 4, 2024
@mholt
Copy link
Member

mholt commented Sep 4, 2024

That's very clever! Thanks for sharing.

@francislavoie
Copy link
Member

note: {{placeholder "re.datamd.1" | readFile | markdown}} doesn't work

That's because {re.*} is a Caddyfile shortcut (the braces matter) but if you use it in a template that shortcut replacement (done via a textual regexp on the Caddyfile content before parsing) doesn't happen. So you need to use the long form, http.regexp.* instead.

casperdcl added a commit to SyneRBI/PETRIC-backend that referenced this issue Sep 4, 2024
casperdcl added a commit to SyneRBI/PETRIC-backend that referenced this issue Sep 5, 2024
casperdcl added a commit to SyneRBI/PETRIC-backend that referenced this issue Sep 5, 2024
casperdcl added a commit to SyneRBI/PETRIC-backend that referenced this issue Sep 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature ⚙️ New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants