lightbend/paradox

Unable to define the source_url base when the input source is a generated directory

AlexITC opened this issue · 7 comments

I'm using mdoc with paradox, which means that I set the paradox source to be from the mdoc output, specifically Compile / paradox / sourceDirectory := mdocOut.value.

Unfortunately, this means that I have dead-links on every page, because they link to the mdoc output directory instead of the proper source.

This is from the page footers with this content:

 The source code for this page can be found here. 

From my research, this gets rendered from the source_url variable, and I see no way to override this to the proper source, any hints appreciated.

I am having the same issue.
The url is accessed in themes/generic/src/main/assets/source.st which is used in themes/generic/src/main/assets/page.st.

I think that source_url is exposed to the template via the PageContents.getSource_url (imposed by PageTemplate.Contents).
getSource_url is based on GithubLink.href which uses GithubResolver.treeUrl defined in terms of GithubResolver.baseUrl that reads the github.base_url property.
Writer.Context is passed to the creation of GithubLink and its properties are used to initialize variables used in PropertyUrl.collect

Initally I thought that maybe this or this ++ could be responsible. If this is the case, both the properties passed to process and those coming from the page contain github.base_url and one is taken in favor of the other (as map keys must be unique).
pageProperties is used to build the Writer.Context which is then used to build a PageContents.

However if in my project sbt console I run show Paradox/paradoxProperties, github.base_url contains the correct address to the folder containing my md files. So a conflict is not the problem.

I forget to post that I found a way to solve this, the drawback is that it very simple and link sources from a single branch, it involves overriding the source url template, and a simple js to fix the source url.

src/main/paradox/_template/source.st:

<script type="text/javascript" src="$page.base$js/link_fix.js"></script>

$if(page.source_url)$
<div class="source-github">
The source code for this page can be found <a id="source-link" href="$page.source_url$">here</a>.
</div>
$endif$

<script type="text/javascript">jQuery(function(){sourceUrlFix('$page.source_url$')});</script>

src/main/paradox/_template/js/link_fix.js (this just creates a function to link the correct source:

function sourceUrlFix(sourceUrl) {
    // TODO: Use any branch instead of master
    $("#source-link").attr("href", sourceUrl.replace("tree/master/docs/target/mdoc", "tree/master/docs/src/main/paradox"))
}

Thanks for sharing your workaround @AlexITC! However, I think it would be better if we could fix the root cause of the problem instead. I think the issue should be re-opened.

I agree wtih @julienrf . I do not like this solution and I think the issue should be still be open.

It is not an easy fix but I think it is very important. Paradox is one of the very few resources allowing to create a site without relying on node, yarn, jekyll or ruby and having a broken link on each page does not look great.

I know it is not an ideal workaround but at least, there is a way.

I'd have preferred to have a plugin option to either disable the generation, or to set the right source url.

nafg commented

This is pretty important