diff --git a/src/main/java/sirius/biz/tycho/kb/SynchronizeArticlesTask.java b/src/main/java/sirius/biz/tycho/kb/SynchronizeArticlesTask.java index c638309e7..e5de7ca1c 100644 --- a/src/main/java/sirius/biz/tycho/kb/SynchronizeArticlesTask.java +++ b/src/main/java/sirius/biz/tycho/kb/SynchronizeArticlesTask.java @@ -26,6 +26,7 @@ import sirius.pasta.tagliatelle.Template; import sirius.pasta.tagliatelle.rendering.GlobalRenderContext; +import java.io.File; import java.time.LocalDate; import java.util.Arrays; import java.util.List; @@ -36,7 +37,10 @@ /** * Scans all available articles and turns them into {@link KnowledgeBaseEntry knowledge base entries}. *

- * Note that this also deletes outdated entries or empty chapters. + * Note: + * - the task also deletes outdated entries or empty chapters. + * - the task ignores everything in the "kb/parts" directory as this is meant for shared components. + * - the task ignores every template which has a parent directory called "parts" as this is meant for article components. */ @Register(framework = KnowledgeBase.FRAMEWORK_KNOWLEDGE_BASE) public class SynchronizeArticlesTask implements EndOfDayTask { @@ -93,7 +97,10 @@ private void synchronizeArticles() { String syncId = keyGenerator.generateId(); Sirius.getClasspath() .find(Pattern.compile("(default/|customizations/[^/]+/)?kb/.*\\.pasta")) - .forEach(matcher -> updateArticle(cleanupTemplatePath(matcher.group(0)), syncId)); + .map(matcher -> cleanupTemplatePath(matcher.group(0))) + .filter(templatePath -> !isTemplateInsidePartsDirectory(templatePath)) + .filter(templatePath -> !isTemplateAPartOfAnArticle(templatePath)) + .forEach(templatePath -> updateArticle(templatePath, syncId)); elastic.refresh(KnowledgeBaseEntry.class); cleanupOldEntries(syncId); @@ -106,6 +113,38 @@ private void synchronizeArticles() { knowledgeBase.resetLanguages(); } + /** + * Determines if the given template is part of an article. + *

+ * Note: + * - Every template which is inside a parent directory called "parts" is considered a component of an article. + *

+ * Example: + * kb/integration/document/parts + * The main document article is located at /document. Its components are located in /document/parts. + * + * @param templatePath the template path to check + * @return true if the template is part of an article, false otherwise + */ + private static boolean isTemplateAPartOfAnArticle(String templatePath) { + String parentDir = new File(templatePath).getParentFile().getName(); + return "parts".equals(parentDir); + } + + /** + * Determines if the given template path is located inside the "kb/parts" directory. + *

+ * Note: + * - The kb/parts directory (and sub-dirs) only contains article components which are not articles on their own. + * - The directory is meant for shared components which are used by multiple articles. + * + * @param templatePath the template path to check + * @return true if the template path is located inside the "kb/parts" directory, false otherwise + */ + private static boolean isTemplateInsidePartsDirectory(String templatePath) { + return templatePath.contains("kb/parts/"); + } + private String cleanupTemplatePath(String templatePath) { if (templatePath.startsWith("default/")) { return "/" + templatePath.substring(8);