forked from quarkusio/quarkusio.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
/
unlinkedguides.java
executable file
·81 lines (66 loc) · 2.42 KB
/
unlinkedguides.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
///usr/bin/env jbang "$0" "$@" ; exit $?
//DEPS info.picocli:picocli:4.5.0
//DEPS org.yaml:snakeyaml:1.29
import picocli.CommandLine;
import picocli.CommandLine.Command;
import picocli.CommandLine.Parameters;
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.representer.Representer;
import org.yaml.snakeyaml.introspector.BeanAccess;
import java.io.File;
import java.io.FileReader;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.stream.Collectors;
@Command(name = "UnlinkedGuides", mixinStandardHelpOptions = true, version = "UnlinkedGuides 0.1",
description = "UnlinkedGuides made with jbang")
class unlinkedguides implements Callable<Integer> {
@Parameters(index = "0", description = "The version of guides", defaultValue = "latest")
private String version;
public static void main(String... args) {
int exitCode = new CommandLine(new unlinkedguides()).execute(args);
System.exit(exitCode);
}
@Override
public Integer call() throws Exception {
Representer representer = new Representer();
representer.getPropertyUtils().setSkipMissingProperties(true);
Yaml yaml = new Yaml(representer);
yaml.setBeanAccess(BeanAccess.FIELD);
String guidesPath = "./_data/guides-" + version + ".yaml";
Categories cats = yaml.loadAs(new FileReader(guidesPath), Categories.class);
System.out.println("Unlinked guides in " + guidesPath);
List<String> guides = cats.categories.stream()
.flatMap(c -> c.guides.stream())
.map(g -> g.url.replace("/guides/", ""))
.collect(Collectors.toList());
Files.find(Path.of(getGuidesPath(version)), 1, (p, a) -> p.toString().endsWith(".adoc"))
.map(p -> p.getFileName().toString().replace(".adoc", ""))
.filter(p -> !guides.contains(p))
.forEach(System.out::println);
return 0;
}
String getGuidesPath(String version) {
if (version.equals("latest")) {
return "./_guides";
} else {
return "./_versions/" + version + "/guides";
}
}
}
class Categories {
List<Category> categories;
}
class Category {
List<Guide> guides;
String category;
// String catId;
}
class Guide {
String title;
String url;
String description;
String keywords;
}