Skip to content

Commit

Permalink
Adjust REGEX to get FM (#173)
Browse files Browse the repository at this point in the history
* Solve issue #158

* Apply suggestions from code review

---------

Co-authored-by: Andy Damevin <[email protected]>
  • Loading branch information
mcruzdev and ia3andy authored Oct 11, 2024
1 parent 8693bff commit e0632b7
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
public class RoqFrontMatterScanProcessor {
private static final Logger LOGGER = org.jboss.logging.Logger.getLogger(RoqFrontMatterScanProcessor.class);
private static final Set<String> SUPPORTED_LAYOUT_EXTENSIONS = Set.of(".md", "markdown", ".html", ".asciidoc", ".adoc");
public static final Pattern FRONTMATTER_PATTERN = Pattern.compile("^---\\v.*\\v---\\v", Pattern.DOTALL);
public static final Pattern FRONTMATTER_PATTERN = Pattern.compile("^---\\v.*?---\\v", Pattern.DOTALL);
private static final String DRAFT_KEY = "draft";
private static final String DATE_KEY = "date";
private static final String LAYOUT_KEY = "layout";
Expand Down Expand Up @@ -283,7 +283,7 @@ private static String getFrontMatter(String content) {
}

private static String stripFrontMatter(String content) {
return FRONTMATTER_PATTERN.matcher(content).replaceAll("");
return FRONTMATTER_PATTERN.matcher(content).replaceFirst("");
}

private static boolean hasFrontMatter(String content) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,10 @@ public void testDateFileName() {
.body("html.body.article.span", equalTo("2020-10-24T12:00Z[UTC]"));
}

@Test
public void testFrontMatterInContent() {
RestAssured.when().get("/bar/posts/markdown-post-k8s").then().statusCode(200).log().ifValidationFails()
.body(containsString("A K8S post made with markdown"));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
k8s: true
layout: post
title: K8S Post
description: This aims to solve the issue 158
foo: bar
date: 2024-09-09 10:45:00 +0200
---

# A K8S post made with markdown

```yaml
---
kind: Deployment
---
kind: Pod
```
Hello!

0 comments on commit e0632b7

Please sign in to comment.