-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Convert errorCodes using markdown
- Loading branch information
Showing
16 changed files
with
259 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { promises as fsPromises } from 'fs'; | ||
import marked from 'marked'; | ||
import { BasicRepresentation } from '../../ldp/representation/BasicRepresentation'; | ||
import type { Representation } from '../../ldp/representation/Representation'; | ||
import type { TemplateEngine } from '../../pods/generate/TemplateEngine'; | ||
import { TEXT_HTML, TEXT_MARKDOWN } from '../../util/ContentTypes'; | ||
import { resolveAssetPath } from '../../util/PathUtil'; | ||
import { readableToString } from '../../util/StreamUtil'; | ||
import type { RepresentationConverterArgs } from './RepresentationConverter'; | ||
import { TypedRepresentationConverter } from './TypedRepresentationConverter'; | ||
|
||
/** | ||
* Converts markdown data to HTML. | ||
* The generated HTML will be injected into the given template using the parameter `htmlBody`. | ||
* A standard markdown string will be converted to a <p> tag, so html and body tags should be part of the template. | ||
* In case the markdown body starts with a header (#), that value will also be used as `title` parameter. | ||
*/ | ||
export class MarkdownToHtmlConverter extends TypedRepresentationConverter { | ||
private readonly engine: TemplateEngine; | ||
private readonly templatePath: string; | ||
|
||
public constructor(engine: TemplateEngine, templatePath: string) { | ||
super(TEXT_MARKDOWN, TEXT_HTML); | ||
this.engine = engine; | ||
this.templatePath = resolveAssetPath(templatePath); | ||
} | ||
|
||
public async handle({ representation }: RepresentationConverterArgs): Promise<Representation> { | ||
const markdown = await readableToString(representation.data); | ||
|
||
// See if there is a title we can use | ||
const match = /^\s*#+\s*([^\n]+)\n/u.exec(markdown); | ||
const title = match?.[1]; | ||
|
||
const htmlBody = marked(markdown); | ||
|
||
const template = await fsPromises.readFile(this.templatePath, 'utf8'); | ||
const html = this.engine.apply(template, { htmlBody, title }); | ||
|
||
return new BasicRepresentation(html, representation.metadata, TEXT_HTML); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
### Requests to `{{ path }}` are not supported | ||
The Community Solid Server received a request for `{{ path }}`, which is not configured. | ||
Here are some things you can try to fix this: | ||
- Have you started the server with the right hostname? | ||
- If you are running the server behind a reverse proxy, did you set up the `Forwarded` header correctly? |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# {{ name }} | ||
|
||
{{#if description}} | ||
{{{ description }}} | ||
{{/if}} | ||
|
||
## Technical details | ||
{{ message }} | ||
|
||
{{#if stack}} | ||
``` | ||
{{ stack }} | ||
``` | ||
{{/if}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"/> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"/> | ||
{{#if title}} | ||
<title>{{ title }}</title> | ||
{{/if}} | ||
</head> | ||
<body> | ||
{{! Triple braces to prevent HTML escaping }} | ||
{{{ htmlBody }}} | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.