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

98 seo module #109

Merged
merged 9 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ cms-server/modules/thymeleaf-module
cms-server/modules/freemarker-module
cms-server/modules/ui-module
cms-server/modules/pug-module
cms-server/modules/search-module
cms-server/modules/search-module
cms-server/modules/seo-module
2 changes: 1 addition & 1 deletion cms-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.github.thmarx.cms</groupId>
<artifactId>cms-parent</artifactId>
<version>2.14.0</version>
<version>2.15.0</version>
</parent>
<artifactId>cms-api</artifactId>
<packaging>jar</packaging>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* #L%
*/

import com.github.thmarx.cms.api.db.DB;
import com.github.thmarx.cms.api.eventbus.EventBus;
import com.github.thmarx.cms.api.theme.Theme;
import com.github.thmarx.modules.api.Context;
Expand All @@ -43,7 +44,7 @@ public class CMSModuleContext implements Context {
@Getter
private final ServerProperties serverProperties;
@Getter
private final ModuleFileSystem fileSystem;
private final DB db;
@Getter
private final EventBus eventBus;
@Getter
Expand Down
52 changes: 52 additions & 0 deletions cms-api/src/main/java/com/github/thmarx/cms/api/db/Content.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package com.github.thmarx.cms.api.db;

/*-
* #%L
* cms-api
* %%
* Copyright (C) 2023 Marx-Software
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/gpl-3.0.html>.
* #L%
*/

import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.function.BiFunction;

/**
*
* @author thmar
*/
public interface Content {
boolean isVisible (String uri);

List<ContentNode> listSections(Path contentFile);

List<ContentNode> listContent(final Path base, final String start);

List<ContentNode> listDirectories(final Path base, final String start);

Optional<ContentNode> byUri (final String uri);

Optional<Map<String,Object>> getMeta(final String uri);

public <T> ContentQuery<T> query(final BiFunction<ContentNode, Integer, T> nodeMapper);

public <T> ContentQuery<T> query(final String startURI, final BiFunction<ContentNode, Integer, T> nodeMapper);
}
101 changes: 101 additions & 0 deletions cms-api/src/main/java/com/github/thmarx/cms/api/db/ContentNode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package com.github.thmarx.cms.api.db;

/*-
* #%L
* cms-api
* %%
* Copyright (C) 2023 Marx-Software
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/gpl-3.0.html>.
* #L%
*/

import com.github.thmarx.cms.api.Constants;
import com.github.thmarx.cms.api.PreviewContext;
import com.github.thmarx.cms.api.utils.SectionUtil;
import java.time.Instant;
import java.time.LocalDate;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
*
* @author t.marx
*/
public record ContentNode(String uri, String name, Map<String, Object> data,
boolean directory, Map<String, ContentNode> children, LocalDate lastmodified) {

public ContentNode(String uri, String name, Map<String, Object> data, boolean directory, Map<String, ContentNode> children) {
this(uri, name, data, directory, children, LocalDate.now());
}

public ContentNode(String uri, String name, Map<String, Object> data, boolean directory) {
this(uri, name, data, directory, new HashMap<String, ContentNode>(), LocalDate.now());
}

public ContentNode(String uri, String name, Map<String, Object> data) {
this(uri, name, data, false, new HashMap<String, ContentNode>(), LocalDate.now());
}

public ContentNode(String uri, String name, Map<String, Object> data, LocalDate lastmodified) {
this(uri, name, data, false, new HashMap<String, ContentNode>(), lastmodified);
}

public boolean isDirectory() {
return directory;
}

public boolean isHidden() {
return name.startsWith(".");
}

public boolean isDraft() {
return (boolean) data().getOrDefault(Constants.MetaFields.DRAFT, false);
}

public boolean isPublished() {
if (PreviewContext.IS_PREVIEW.get()) {
return true;
}
var localDate = (Date) data.getOrDefault(Constants.MetaFields.PUBLISHED, Date.from(Instant.now()));
var now = Date.from(Instant.now());
return !isDraft() && (localDate.before(now) || localDate.equals(now));
}

public boolean isSection() {
return SectionUtil.isSection(name);
}

@Override
public boolean equals (Object other) {

if (this == other) {
return true;
}

if (other == null) {
return false;
}

if (!(other instanceof ContentNode)) {
return false;
}

var otherNode = (ContentNode)other;

return uri.equals(otherNode.uri);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package com.github.thmarx.cms.api.db;

/*-
* #%L
* cms-api
* %%
* Copyright (C) 2023 Marx-Software
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/gpl-3.0.html>.
* #L%
*/

import com.github.thmarx.cms.api.db.ContentNode;
import java.util.List;
import java.util.Map;

/**
*
* @author t.marx
*/
public interface ContentQuery<T> {

int count();

ContentQuery<T> excerpt(final int excerptLength);

List<T> get(final long offset, final long size);

List<T> get(final int offset, final int size);

List<T> get();

Map<Object, List<ContentNode>> groupby(final String field);

Sort<T> orderby(final String field);

ContentQuery<T> where(final String field, final Object value);

ContentQuery<T> where(final String field, final String operator, final Object value);

ContentQuery<T> whereContains(final String field, final Object value);

ContentQuery<T> whereContainsNot(final String field, final Object value);

ContentQuery<T> whereIn(final String field, final Object... value);

ContentQuery<T> whereIn(final String field, final List<Object> value);

ContentQuery<T> whereNotIn(final String field, final Object... value);

ContentQuery<T> whereNotIn(final String field, final List<Object> value);

public static interface Sort<T> {
public ContentQuery<T> asc();

public ContentQuery<T> desc();
}
}
34 changes: 34 additions & 0 deletions cms-api/src/main/java/com/github/thmarx/cms/api/db/DB.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.github.thmarx.cms.api.db;

/*-
* #%L
* cms-api
* %%
* Copyright (C) 2023 Marx-Software
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/gpl-3.0.html>.
* #L%
*/

/**
*
* @author thmar
*/
public interface DB extends AutoCloseable{

public DBFileSystem getFileSystem();

public Content getContent();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.github.thmarx.cms.api.db;

/*-
* #%L
* cms-api
* %%
* Copyright (C) 2023 Marx-Software
* %%
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/gpl-3.0.html>.
* #L%
*/

import java.io.IOException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;

/**
*
* @author thmar
*/
public interface DBFileSystem {
Path resolve(String path);

String loadContent(final Path file) throws IOException;

List<String> loadLines(final Path file) throws IOException;

String loadContent(final Path file, final Charset charset) throws IOException;

List<String> loadLines(final Path file, final Charset charset) throws IOException;
}
2 changes: 1 addition & 1 deletion cms-filesystem/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>com.github.thmarx.cms</groupId>
<artifactId>cms-parent</artifactId>
<version>2.14.0</version>
<version>2.15.0</version>
</parent>
<artifactId>cms-filesystem</artifactId>
<packaging>jar</packaging>
Expand Down
Loading