Skip to content

Commit 0ac076d

Browse files
authored
Merge pull request #223 from JavaEden/dev
Release 0.15.3
2 parents 8718c86 + a36d64f commit 0ac076d

File tree

25 files changed

+373
-99
lines changed

25 files changed

+373
-99
lines changed

OrchidCore/src/main/java/com/eden/orchid/api/theme/pages/OrchidReference.java

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ public final class OrchidReference {
3636
*/
3737
private String extension;
3838

39+
/**
40+
* The querystring for linking to external pages
41+
*/
42+
private String query;
43+
3944
/**
4045
* The output extension of the file.
4146
*/
@@ -85,6 +90,7 @@ public OrchidReference(OrchidReference source) {
8590
this.fileName = source.fileName;
8691
this.extension = source.extension;
8792
this.id = source.id;
93+
this.query = source.query;
8894
this.title = source.title;
8995
this.usePrettyUrl = source.usePrettyUrl;
9096
}
@@ -197,7 +203,23 @@ public String getPath() {
197203
public String getPathSegment(int segmentIndex) {
198204
String path = getPath();
199205
String[] segments = path.split("/");
200-
return segments[segmentIndex];
206+
207+
final int actualIndex;
208+
// we have a positive index
209+
if(segmentIndex >= 0 && segmentIndex <= segments.length - 1) {
210+
actualIndex = segmentIndex;
211+
}
212+
// we have a negative index, search from end
213+
else if(segmentIndex < 0 && Math.abs(segmentIndex) <= segments.length) {
214+
actualIndex = segments.length - Math.abs(segmentIndex);
215+
}
216+
217+
// index not in range
218+
else {
219+
throw new ArrayIndexOutOfBoundsException(segmentIndex);
220+
}
221+
222+
return segments[actualIndex];
201223
}
202224

203225
public String[] getPathSegments() {
@@ -270,6 +292,11 @@ public String getServerPath() {
270292
output += id;
271293
}
272294

295+
if (!EdenUtils.isEmpty(query)) {
296+
output += "?";
297+
output += query;
298+
}
299+
273300
return OrchidUtils.normalizePath(output);
274301
}
275302

@@ -315,6 +342,7 @@ public JSONObject toJSON() {
315342
referenceJson.put("fileName", this.fileName);
316343
referenceJson.put("extension", this.extension);
317344
referenceJson.put("id", this.id);
345+
referenceJson.put("query", this.query);
318346
referenceJson.put("title", this.title);
319347
referenceJson.put("usePrettyUrl", this.usePrettyUrl);
320348

@@ -328,6 +356,7 @@ public static OrchidReference fromJSON(OrchidContext context, JSONObject source)
328356
newReference.fileName = source.optString("fileName");
329357
newReference.extension = source.optString("extension");
330358
newReference.id = source.optString("id");
359+
newReference.query = source.optString("query");
331360
newReference.title = source.optString("title");
332361
newReference.usePrettyUrl = source.optBoolean("usePrettyUrl");
333362
return newReference;
@@ -349,6 +378,11 @@ public static OrchidReference fromUrl(OrchidContext context, String title, Strin
349378
newReference.path = OrchidUtils.normalizePath(parsedUrl.getPath().replaceAll(FilenameUtils.getName(parsedUrl.getPath()), ""));
350379
newReference.title = title;
351380
newReference.extension = FilenameUtils.getExtension(FilenameUtils.getName(url));
381+
newReference.outputExtension = newReference.extension;
382+
newReference.query = parsedUrl.getQuery();
383+
newReference.id = parsedUrl.getRef();
384+
newReference.setUsePrettyUrl(false);
385+
352386
return newReference;
353387
}
354388
catch (Exception e) {
@@ -408,5 +442,13 @@ public void setUsePrettyUrl(boolean usePrettyUrl) {
408442
this.usePrettyUrl = usePrettyUrl;
409443
}
410444

445+
public String getQuery() {
446+
return query;
447+
}
448+
449+
public OrchidReference setQuery(String query) {
450+
this.query = query;
451+
return this;
452+
}
411453
}
412454

OrchidCore/src/main/kotlin/com/eden/orchid/impl/themes/menus/LinkMenuItem.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import com.eden.common.util.EdenUtils
44
import com.eden.orchid.api.OrchidContext
55
import com.eden.orchid.api.options.annotations.Description
66
import com.eden.orchid.api.options.annotations.Option
7-
import com.eden.orchid.api.theme.menus.OrchidMenuFactory
87
import com.eden.orchid.api.theme.menus.MenuItem
8+
import com.eden.orchid.api.theme.menus.OrchidMenuFactory
99
import com.eden.orchid.api.theme.pages.OrchidExternalPage
1010
import com.eden.orchid.api.theme.pages.OrchidReference
1111
import com.eden.orchid.utilities.OrchidUtils
@@ -36,12 +36,18 @@ constructor(
3636

3737
if (!EdenUtils.isEmpty(title) && !EdenUtils.isEmpty(url)) {
3838
var reference: OrchidReference? = null
39+
40+
// if link is just a slash, it is a link to the homepage
3941
if (url == "/") {
4042
url = context.baseUrl
4143
}
44+
45+
// if the URL is not external, apply this site's base URL to make it absolute
4246
else if (!OrchidUtils.isExternal(url)) {
4347
url = OrchidUtils.applyBaseUrl(context, url)
4448
}
49+
50+
// if the link is an ID, it should be a link to the current page at that ID
4551
else if (url.startsWith("#")) {
4652
reference = OrchidReference(page.reference)
4753
reference.id = url.substring(1)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
version: '0.15.3'
3+
---
4+
5+
- Updates OrchidBible dependency to hit correct endpoints and improves usability
6+
- Parses external URLs better
7+
- Passes command line args directly through to Dokka so Gradle can supply the proper documentation classpath

OrchidCore/src/orchid/resources/config.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,8 @@ services:
4646
stages:
4747
- type: githubReleases
4848
repo: 'JavaEden/Orchid'
49+
50+
kotlindoc:
51+
sourceDirs:
52+
- '../../main/java'
53+
- '../../main/kotlin'

OrchidCore/src/orchid/resources/pages/plugins/OrchidKotlindoc/index.md

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,29 @@ services:
3737
{% endhighlight %}
3838

3939
Orchid itself is written in Kotlin and documented with this Kotlindoc plugin. You can preview the generated
40-
documentation {{anchor('here', 'com.eden.orchid')}}.
40+
documentation {{anchor('here', 'com.eden.orchid')}}.
41+
42+
### Dokka Configuration
43+
44+
This plugin delegates to Dokka to provide the documentation model. It will fetch the necessary jars and [run Dokka using
45+
the command line](https://github.com/Kotlin/dokka#using-the-command-line), and you are able to add any additional
46+
arguments you wish.
47+
48+
First, you may specify the `--kotlindocClasspath` flag to Orchid, which will forward this value to Dokka's `-classpath`
49+
arg. Example usage when running Orchid from Gradle looks like the following:
50+
51+
{% highlight 'groovy' %}
52+
orchid {
53+
...
54+
args = ["--kotlindocClasspath", getModuleClasspathString()]
55+
}
56+
{% endhighlight %}
57+
58+
In addition, you may specify a full list of args in your `config.yml` which will be passed-through to Dokka.
59+
60+
{% highlight 'yaml' %}
61+
kotlindoc:
62+
args:
63+
- '-classpath'
64+
- '...'
65+
{% endhighlight %}

OrchidCore/src/orchid/resources/templates/includes/officialPlugin.peb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
{%- block homepageUrl -%}{{- page.link~'/docs' -}} {%- endblock -%}
44
{%- block homepageText -%}Full Documentation {%- endblock -%}
5-
{%- block dependency -%}io.github.javaeden.orchid:{{- page.reference.originalFileName -}}:{{ site.version }}{%- endblock -%}
5+
{%- block dependency -%}io.github.javaeden.orchid:{{- page.reference.pathSegments|last -}}:{{ site.version }}{%- endblock -%}
66
{%- block vcsUrl -%}https://github.com/JavaEden/Orchid {%- endblock -%}
77
{%- block vcsIcon -%}github {%- endblock -%}
88
{%- block vcsRepo -%}JavaEden/Orchid {%- endblock -%}

OrchidCore/src/orchid/resources/templates/includes/officialTheme.peb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
{%- block homepageUrl -%}{{- page.link~'/docs' -}} {%- endblock -%}
44
{%- block homepageText -%}Full Documentation {%- endblock -%}
5-
{%- block dependency -%}io.github.javaeden.orchid:{{- page.reference.originalFileName -}}:{{ site.version }}{%- endblock -%}
5+
{%- block dependency -%}io.github.javaeden.orchid:{{- page.reference.pathSegments|last -}}:{{ site.version }}{%- endblock -%}
66
{%- block vcsUrl -%}https://github.com/JavaEden/Orchid {%- endblock -%}
77
{%- block vcsIcon -%}github {%- endblock -%}
88
{%- block vcsRepo -%}JavaEden/Orchid {%- endblock -%}

OrchidCore/src/orchid/resources/wiki/user-manual/publication/deployment-pipelines.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,4 @@ There are several publishers available in `OrchidCore`, but more may be availabl
108108
- {{anchor('Script')}} - Execute arbitrary shell scripts
109109
- {{anchor('Netlify')}} - Upload your site to Netlify
110110
- {{anchor('GitHub Pages')}} - Push your site to GitHub Pages
111+
- {{anchor('GitHub Releases')}} - Create a release on Github

OrchidCore/src/orchid/resources/wiki/user-manual/publication/github-pages.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,16 @@ This publisher expects Git to be installed locally on your system, as it delegat
1111
directly to shell commands.
1212
{% endalert %}
1313

14-
To use the `ghPages` publisher, you'll need to provide Orchid with a `githubToken` containing a Personal Access Token
15-
from Netlify. Since PATs are confidential and allow anyone who has it complete access to your account, you should set
16-
this as an environment variable and add it to your Gradle orchid config from that variable rather than committing it to
17-
source control.
14+
To use the `githubReleases` publisher, you'll need to provide Orchid with a `githubToken` containing a Personal Access
15+
Token from Github. Since PATs are confidential and allow anyone who has it complete access to your account, you should
16+
set this as an environment variable and add it to your Gradle orchid config from that variable rather than committing it
17+
to source control.
1818

1919
{% highlight 'groovy' %}
2020
orchid {
2121
...
22-
args = ["githubToken ${System.getenv('GITHUB_TOKEN')}"]
22+
githubToken = "${System.getenv('GITHUB_TOKEN')}"
23+
// or 'githubToken' in an environment variable without this line
2324
}
2425
{% endhighlight %}
2526

@@ -39,6 +40,7 @@ services:
3940
- type: ghPages
4041
username: 'cjbrooks12'
4142
repo: 'JavaEden/Orchid'
43+
# or
4244
- type: ghPages
4345
username: 'cjbrooks12'
4446
repo: 'cjbrooks12.github.io' # becomes cjbrooks12/cjbrooks12.github.io

OrchidCore/src/orchid/resources/wiki/user-manual/publication/github-releases.md

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -4,46 +4,35 @@ description: 'Create a Release on Github from your Changelog.'
44

55
## Description
66

7-
The `ghPages` Publisher allows you to upload your site to GithubPages.
7+
The `githubReleases` Publisher allows you to create a git tag and a Release on Github with notes from your latest
8+
changelog entry.
89

9-
{% alert 'info' %}
10-
This publisher expects Git to be installed locally on your system, as it delegates the entire deployment process
11-
directly to shell commands.
12-
{% endalert %}
13-
14-
To use the `ghPages` publisher, you'll need to provide Orchid with a `githubToken` containing a Personal Access Token
15-
from Netlify. Since PATs are confidential and allow anyone who has it complete access to your account, you should set
16-
this as an environment variable and add it to your Gradle orchid config from that variable rather than committing it to
17-
source control.
10+
To use the `githubReleases` publisher, you'll need to provide Orchid with a `githubToken` containing a Personal Access
11+
Token from Github. Since PATs are confidential and allow anyone who has it complete access to your account, you should
12+
set this as an environment variable and add it to your Gradle orchid config from that variable rather than committing it
13+
to source control.
1814

1915
{% highlight 'groovy' %}
2016
orchid {
2117
...
22-
args = ["githubToken ${System.getenv('GITHUB_TOKEN')}"]
18+
githubToken = "${System.getenv('GITHUB_TOKEN')}"
19+
// or 'githubToken' in an environment variable without this line
2320
}
2421
{% endhighlight %}
2522

26-
After your PAT is set up, you'll need to set up your repo on GitHub with a `gh-pages` branch. Orchid will initialize a
27-
new local git repo and push it to this branch, overwriting anything currently in that branch.
28-
29-
The `username` property is the user which issued the PAT, and it is also the organization hosting the repository on
30-
GitHub. You can authenticate with a different user than is hosting the repository by setting the `repo` as
31-
`username/repo`.
23+
The release will be created on the repo specified in the publisher config, specified at `repo` as `username/repo`. The
24+
account the PAT was created for must have write acess to this repo.
3225

3326
## Example Usage
3427

3528
{% highlight 'yaml' %}
3629
services:
37-
publications:
38-
stages:
39-
- type: ghPages
40-
username: 'cjbrooks12'
30+
publications:
31+
stages:
32+
githubReleases:
4133
repo: 'JavaEden/Orchid'
42-
- type: ghPages
43-
username: 'cjbrooks12'
44-
repo: 'cjbrooks12.github.io' # becomes cjbrooks12/cjbrooks12.github.io
4534
{% endhighlight %}
4635

4736
## API Documentation
4837

49-
{% docs className='com.eden.orchid.impl.publication.GithubPagesPublisher' tableClass='table' tableLeaderClass='hidden' %}
38+
{% docs className='com.eden.orchid.changelog.publication.GithubReleasesPublisher' tableClass='table' tableLeaderClass='hidden' %}

OrchidCore/src/orchid/resources/wiki/user-manual/publication/netlify.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ source control.
1414
{% highlight 'groovy' %}
1515
orchid {
1616
...
17-
args = ["netlifyToken ${System.getenv('NETLIFY_TOKEN')}"]
17+
args = ["netlifyToken", "${System.getenv('NETLIFY_TOKEN')}"]
1818
}
1919
{% endhighlight %}
2020

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
package com.eden.orchid.api.theme.pages
2+
3+
import com.caseyjbrooks.clog.Clog
4+
import com.eden.orchid.api.OrchidContext
5+
import org.junit.jupiter.api.BeforeEach
6+
import org.junit.jupiter.params.ParameterizedTest
7+
import org.junit.jupiter.params.provider.CsvSource
8+
import org.mockito.Mockito.mock
9+
import strikt.api.expectThat
10+
import strikt.api.expectThrows
11+
import strikt.assertions.isEqualTo
12+
13+
class OrchidReferenceTest {
14+
15+
lateinit var context: OrchidContext
16+
17+
@BeforeEach
18+
internal fun setUp() {
19+
context = mock(OrchidContext::class.java)
20+
}
21+
22+
@ParameterizedTest
23+
@CsvSource(
24+
"/one/two/three/four/five, 0, one",
25+
"/one/two/three/four/five, 1, two",
26+
"/one/two/three/four/five, 2, three",
27+
"/one/two/three/four/five, 3, four",
28+
"/one/two/three/four/five, 4, five",
29+
30+
"/one/two/three/four/five, -5, one",
31+
"/one/two/three/four/five, -4, two",
32+
"/one/two/three/four/five, -3, three",
33+
"/one/two/three/four/five, -2, four",
34+
"/one/two/three/four/five, -1, five"
35+
)
36+
fun testGetPathSegment(path: String, index: Int, segment: String) {
37+
val ref = OrchidReference(context, path)
38+
39+
expectThat(ref.getPathSegment(index)).isEqualTo(segment)
40+
}
41+
42+
@ParameterizedTest
43+
@CsvSource(
44+
"/one/two/three/four/five, 5",
45+
"/one/two/three/four/five, -6"
46+
)
47+
fun testGetPathSegmentThrowing(path: String, index: Int) {
48+
val ref = OrchidReference(context, path)
49+
50+
expectThrows<ArrayIndexOutOfBoundsException> { ref.getPathSegment(index) }
51+
}
52+
53+
@ParameterizedTest
54+
@CsvSource(
55+
// basic examples
56+
"http://www.example.com/example , , ",
57+
"https://www.example.com/example , , ",
58+
"https://www.example.com/example#one , one, ",
59+
"https://www.example.com/example?one=two , , one=two ",
60+
"https://www.example.com/example?one=two&three=four, , one=two&three=four",
61+
62+
// more complex examples
63+
"http://www.example.com/example.js , , ",
64+
"http://www.example.com/example/index , , ",
65+
"http://www.example.com/example/index.js , , ",
66+
"http://www.example.com/example/index.html , , "
67+
)
68+
fun testParsingExternalUrls(original: String, id: String?, query: String?) {
69+
val ref = OrchidReference.fromUrl(context, "", original)
70+
71+
Clog.getInstance().setMinPriority(Clog.Priority.VERBOSE)
72+
73+
expectThat(ref) {
74+
get { this.toString() }.isEqualTo(original)
75+
get { this.id }.isEqualTo(id)
76+
get { this.query }.isEqualTo(query)
77+
}
78+
}
79+
80+
}

0 commit comments

Comments
 (0)