Skip to content
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ see wiki for more information: [wiki](https://github.com/thmarx/cms/wiki)
* **BUGFIX** TemplateEngine should use cache only if activated [456](https://github.com/CondationCMS/cms-server/issues/456)
* **MAINTENANCE** multiple dependencies updated
* **MAINTENANCE** maven wrapper added to project
* **MAINTENANCE** Deprecate/replace PathUtil.toURI with PathUtil.toURL [462](https://github.com/CondationCMS/cms-server/issues/462)
* **FEATURE** Developer Experience [PR-440](https://github.com/CondationCMS/cms-server/pull/440)
* **FEATURE** Aliases for content [442](https://github.com/CondationCMS/cms-server/issues/442)
* **FEATURE** Add redirect support for aliases [454](https://github.com/CondationCMS/cms-server/issues/454)
Expand Down
46 changes: 28 additions & 18 deletions cms-api/src/main/java/com/condation/cms/api/utils/PathUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,30 +90,40 @@ public static String toRelativeFile(ReadOnlyFile contentFile, final ReadOnlyFile
return uri;
}

/**
*
* @param contentFile
* @param contentBase
* @return
* @deprecated use PathUtil.toURL instead
*/
@Deprecated(since = "8.0.0")
public static String toURI (final Path contentFile, final Path contentBase) {
return toURL(contentFile, contentBase);
}
/**
*
* @param contentFile
* @param contentBase
* @return
* @deprecated use PathUtil.toURL instead
*/
@Deprecated(since = "8.0.0")
public static String toURI(final ReadOnlyFile contentFile, final ReadOnlyFile contentBase) {
return toURL(contentFile, contentBase);
}

public static String toURL(final Path contentFile, final Path contentBase) {
var relFile = toRelativeFile(contentFile, contentBase);
if (relFile.endsWith("index.md")) {
relFile = relFile.replace("index.md", "");
}

if (relFile.equals("")) {
relFile = "/";
} else if (relFile.endsWith("/")) {
relFile = relFile.substring(0, relFile.lastIndexOf("/"));
}

if (!relFile.startsWith("/")) {
relFile = "/" + relFile;
}
if (relFile.endsWith(".md")) {
relFile = relFile.substring(0, relFile.lastIndexOf(".md"));
}

return relFile;
return toURL(relFile);
}

public static String toURL(final ReadOnlyFile contentFile, final ReadOnlyFile contentBase) {
var relFile = toRelativeFile(contentFile, contentBase);
return toURL(relFile);
}

private static String toURL (String relFile) {
if (relFile.endsWith("index.md")) {
relFile = relFile.replace("index.md", "");
}
Expand Down