Skip to content

Commit 3201215

Browse files
committed
Add JSON description file
This allows to fetch the available documentations.
1 parent 3f02f9c commit 3201215

File tree

5 files changed

+44
-3
lines changed

5 files changed

+44
-3
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ jobs:
6161
libgee-0.8-dev \
6262
git \
6363
libguestfs-gobject-dev \
64+
libjson-glib-dev \
6465
libvaladoc-0.58-dev \
6566
php \
6667
php-curl \

.github/workflows/publish.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ jobs:
3434
libgee-0.8-dev \
3535
git \
3636
libguestfs-gobject-dev \
37+
libjson-glib-dev \
3738
libvaladoc-0.58-dev \
3839
php \
3940
php-curl \

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ libdoclet.so: src/doclet.vala src/linkhelper.vala
5252
$(RM) $(patsubst %.vala,%.c,$^)
5353

5454

55-
GENERATOR_DEPS = gee-0.8 valadoc-$(VALAC_VERSION) gio-2.0
55+
GENERATOR_DEPS = gee-0.8 valadoc-$(VALAC_VERSION) gio-2.0 json-glib-1.0
5656
GENERATOR_VALAFLAGS := $(patsubst %,--pkg=%,$(GENERATOR_DEPS)) --enable-experimental
5757

5858
generator: src/doclet.vala src/linkhelper.vala src/generator.vala

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ On elementary OS or Ubuntu run:
1818
```bash
1919
sudo add-apt-repository ppa:vala-team
2020
sudo apt update
21-
sudo apt install valac valadoc libvaladoc-dev unzip php php-curl
21+
sudo apt install valac valadoc libvaladoc-dev libjson-glib-dev unzip php php-curl
2222
```
2323

2424
Arch or derivatives run:

src/generator.vala

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -723,6 +723,45 @@ public class Valadoc.IndexGenerator : Valadoc.ValadocOrgDoclet {
723723
generate_index (path + ".content.tpl");
724724
}
725725

726+
public void generate_json (string path) {
727+
stdout.printf ("generate JSON ...\n");
728+
729+
string json_path = Path.build_filename (path, "packages.json");
730+
731+
var builder = new Json.Builder ();
732+
733+
builder.begin_object ();
734+
builder.set_member_name ("books");
735+
builder.begin_array ();
736+
Gee.ArrayList<Package> packages = get_sorted_package_list ();
737+
foreach (Package pkg in packages) {
738+
if (!pkg.is_local || regenerate_all_packages || pkg.name in requested_packages) {
739+
builder.begin_object ();
740+
builder.set_member_name ("name");
741+
builder.add_string_value (pkg.name);
742+
builder.set_member_name ("description");
743+
builder.add_string_value (string.joinv ("\n", pkg.description));
744+
if (pkg.devhelp_link != null) {
745+
builder.set_member_name ("book_path");
746+
builder.add_string_value (pkg.devhelp_link);
747+
}
748+
builder.end_object ();
749+
}
750+
}
751+
builder.end_array ();
752+
builder.end_object ();
753+
754+
var generator = new Json.Generator ();
755+
Json.Node root = builder.get_root ();
756+
generator.set_root (root);
757+
try {
758+
generator.to_file (json_path);
759+
} catch (Error e) {
760+
stderr.printf ("%s\n", e.message);
761+
has_error = true;
762+
}
763+
}
764+
726765
public void regenerate_all_known_packages () throws Error {
727766
foreach (var pkg in packages_per_name.values) {
728767
if (pkg is ExternalPackage == false) {
@@ -1362,8 +1401,8 @@ public class Valadoc.IndexGenerator : Valadoc.ValadocOrgDoclet {
13621401

13631402
string index = Path.build_path (Path.DIR_SEPARATOR_S, output_directory, "index.htm");
13641403
generator.generate (index);
1365-
13661404
generator.generate_configs (output_directory);
1405+
generator.generate_json (output_directory);
13671406

13681407
if (reporter.errors > 0) {
13691408
return -1;

0 commit comments

Comments
 (0)