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
Honor nested path in tagspath #569
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -180,5 +180,6 @@ public static String asPath(String path) { | |
return null; | ||
} | ||
return path.replace(File.separator, "/"); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,8 @@ | |
import org.slf4j.LoggerFactory; | ||
|
||
import java.io.File; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
|
||
/** | ||
* Provides Configuration related functions. | ||
|
@@ -56,4 +58,40 @@ public JBakeConfiguration loadConfig(File source) throws ConfigurationException | |
CompositeConfiguration configuration = load(source); | ||
return new DefaultJBakeConfiguration(source, configuration); | ||
} | ||
|
||
/** | ||
* Given a file inside content it return | ||
* the relative path to get to the root. | ||
* | ||
* Example: /content and /content/tags/blog will return '../..' | ||
* | ||
* @param sourceFile the file to calculate relative path for | ||
* @return | ||
*/ | ||
static public String getPathToRoot(JBakeConfiguration config, File rootPath, File sourceFile) { | ||
|
||
Path r = Paths.get(rootPath.toURI()); | ||
Path s = Paths.get(sourceFile.getParentFile().toURI()); | ||
Path relativePath = s.relativize(r); | ||
|
||
StringBuilder sb = new StringBuilder(); | ||
|
||
sb.append(relativePath.toString()); | ||
|
||
if (config.getUriWithoutExtension()) { | ||
sb.append("/.."); | ||
} | ||
if(sb.length()>0) { // added as calling logic assumes / at end. | ||
sb.append("/"); | ||
} | ||
return sb.toString(); | ||
} | ||
|
||
static public String getPathtoDestinationRoot(JBakeConfiguration config, File sourceFile) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Little typo |
||
return getPathToRoot(config, config.getDestinationFolder(), sourceFile); | ||
} | ||
|
||
static public String getPathToContentRoot(JBakeConfiguration config, File sourceFile) { | ||
return getPathToRoot(config, config.getContentFolder(), sourceFile); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On Windows the relative path contains "\" which is wrong in context of an URI for image paths.
Causing some tests on appveyor to fail. https://ci.appveyor.com/project/jbake-org/jbake/builds/20288027
We should replace alle backslashes with slashes here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe the methods should be moved to FileUtil and contain a pointer that we get a URI Path back? Something like getUriPath.... ?