Skip to content

Commit

Permalink
merlin文档删除了yaml内容
Browse files Browse the repository at this point in the history
  • Loading branch information
ganhuone committed Apr 11, 2024
1 parent 6a4a62e commit 6e5ce58
Showing 1 changed file with 0 additions and 51 deletions.
51 changes: 0 additions & 51 deletions merlin/src/main/java/Parse.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,6 @@ public static Map<String, Object> parse(File file) throws Exception {


public static void parseDocsType(Map<String, Object> jsonMap, String fileContent, String fileName) {
String r = "";
if (fileContent.contains("---")) {
fileContent = fileContent.substring(fileContent.indexOf("---") + 3);
if (fileContent.contains("---")) {
r = fileContent.substring(0, fileContent.indexOf("---"));
fileContent = fileContent.substring(fileContent.indexOf("---") + 3);
}
}

Parser parser = Parser.builder().build();
HtmlRenderer renderer = HtmlRenderer.builder().build();
Expand Down Expand Up @@ -95,49 +87,6 @@ public static void parseDocsType(Map<String, Object> jsonMap, String fileContent
jsonMap.put("h5", h5.text());
jsonMap.put("strong", strong.text());

Yaml yaml = new Yaml();
Map<String, Object> ret = yaml.load(r);
String key = "";
Object value = "";

for (Map.Entry<String, Object> entry : ret.entrySet()) {
key = entry.getKey().toLowerCase(Locale.ROOT);
value = entry.getValue();
if (key.equals("date")) {
//需要处理日期不标准导致的存入ES失败的问题。
String dateString = "";
if (value.getClass().getSimpleName().equals("Date")) {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
dateString = format.format(value);
} else {
dateString = value.toString();
}
Pattern pattern = Pattern.compile("\\D"); //匹配所有非数字
Matcher matcher = pattern.matcher(dateString);
dateString = matcher.replaceAll("-");
if (dateString.length() < 10) {
StringBuilder stringBuilder = new StringBuilder(dateString);
if (stringBuilder.charAt(7) != '-') {
stringBuilder.insert(5, "0");
}
if (stringBuilder.length() < 10) {
stringBuilder.insert(8, "0");
}
dateString = stringBuilder.toString();
}
value = dateString;
}
if (key.equals("author") && value instanceof String) {
value = new String[]{value.toString()};
}
if (key.equals("head")) {
continue;
}
if (key.equals("title")) {
key = "specify";
}
jsonMap.put(key, value);
}
if (jsonMap.containsKey("date")) {
jsonMap.put("archives", jsonMap.get("date").toString().substring(0, 7));
}
Expand Down

0 comments on commit 6e5ce58

Please sign in to comment.