metanorma-release 0.2.5 → 0.2.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: fd5a3df2d9c64ed9d7d70d8f4c3fd3646d8c932a4cbffc39c07490e0276e37d9
|
|
4
|
+
data.tar.gz: f688bc55c1dff3751cdc1903e420e64c7503f7716710655c123e034dd0a3a3fb
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8127051648875b3ea36b988542c9ae82954bf68caf4ad91b785543d8ff6518ef95e1caa7d55334a777c22567806fbfa6cd32014812e6b2885388f42997f881d1
|
|
7
|
+
data.tar.gz: 77c9e3f867de101f3e962d674c8ddcabc630b9ba45557afe4c6338af0669a572dee37432b8231887cde7964f143817ea4ee1b50c9549bf2875dcdc76542152fe
|
|
@@ -82,6 +82,7 @@ module Metanorma
|
|
|
82
82
|
option :file_routing, type: :string, default: "by-document",
|
|
83
83
|
desc: "File routing (by-document|flat|by-format)"
|
|
84
84
|
option :cache_dir, type: :string, desc: "Cache directory"
|
|
85
|
+
option :data_dir, type: :string, desc: "Write flattened documents.json for site generators"
|
|
85
86
|
option :include_drafts, type: :boolean, default: false,
|
|
86
87
|
desc: "Include draft releases"
|
|
87
88
|
option :concurrency, type: :numeric, default: 4
|
|
@@ -101,6 +102,7 @@ module Metanorma
|
|
|
101
102
|
output_dir: options[:output_dir],
|
|
102
103
|
file_routing: options[:file_routing],
|
|
103
104
|
cache_dir: options[:cache_dir],
|
|
105
|
+
data_dir: options[:data_dir],
|
|
104
106
|
include_drafts: options[:include_drafts],
|
|
105
107
|
concurrency: options[:concurrency],
|
|
106
108
|
min_documents: options[:min_documents],
|
|
@@ -8,7 +8,8 @@ module Metanorma
|
|
|
8
8
|
Config = Struct.new(
|
|
9
9
|
:source, :organizations, :topic, :repos, :repo_pattern, :local_path,
|
|
10
10
|
:channels, :stages, :output_dir, :file_routing, :cache_dir,
|
|
11
|
-
:include_drafts, :concurrency, :min_documents, :token,
|
|
11
|
+
:data_dir, :include_drafts, :concurrency, :min_documents, :token,
|
|
12
|
+
:create_zip,
|
|
12
13
|
keyword_init: true
|
|
13
14
|
)
|
|
14
15
|
|
|
@@ -24,7 +25,8 @@ module Metanorma
|
|
|
24
25
|
return result unless result.publications.any?
|
|
25
26
|
|
|
26
27
|
index = build_index(result)
|
|
27
|
-
site = Site.new(index: index, output_dir: @config.output_dir
|
|
28
|
+
site = Site.new(index: index, output_dir: @config.output_dir,
|
|
29
|
+
data_dir: @config.data_dir)
|
|
28
30
|
site.write!
|
|
29
31
|
site.enrich!
|
|
30
32
|
site.package! if @config.create_zip
|
|
@@ -46,6 +48,7 @@ module Metanorma
|
|
|
46
48
|
output_dir: merged[:output_dir],
|
|
47
49
|
file_routing: merged[:file_routing],
|
|
48
50
|
cache_dir: merged[:cache_dir] || DEFAULT_CACHE_DIR,
|
|
51
|
+
data_dir: merged[:data_dir],
|
|
49
52
|
include_drafts: merged[:include_drafts],
|
|
50
53
|
concurrency: merged[:concurrency],
|
|
51
54
|
min_documents: merged[:min_documents],
|
|
@@ -73,6 +76,7 @@ module Metanorma
|
|
|
73
76
|
output_dir: cli_options[:output_dir] || file_data["output_dir"],
|
|
74
77
|
file_routing: cli_options[:file_routing] || file_data["file_routing"],
|
|
75
78
|
cache_dir: cli_options[:cache_dir] || file_data["cache_dir"],
|
|
79
|
+
data_dir: cli_options[:data_dir] || file_data["data_dir"],
|
|
76
80
|
include_drafts: cli_options[:include_drafts] || file_data["include_drafts"],
|
|
77
81
|
concurrency: cli_options[:concurrency] || file_data["concurrency"],
|
|
78
82
|
min_documents: cli_options[:min_documents] || file_data["min_documents"],
|
|
@@ -9,9 +9,10 @@ module Metanorma
|
|
|
9
9
|
class Site
|
|
10
10
|
attr_reader :index, :output_dir
|
|
11
11
|
|
|
12
|
-
def initialize(index:, output_dir:)
|
|
12
|
+
def initialize(index:, output_dir:, data_dir: nil)
|
|
13
13
|
@index = index
|
|
14
14
|
@output_dir = output_dir
|
|
15
|
+
@data_dir = data_dir
|
|
15
16
|
end
|
|
16
17
|
|
|
17
18
|
def write!
|
|
@@ -22,22 +23,49 @@ module Metanorma
|
|
|
22
23
|
def enrich!
|
|
23
24
|
return if index.empty?
|
|
24
25
|
|
|
25
|
-
documents =
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
documents = enrich_documents
|
|
27
|
+
write_relaton_index(documents)
|
|
28
|
+
write_data_file(documents) if @data_dir
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def package!(zip_path: nil)
|
|
32
|
+
require "zip"
|
|
28
33
|
|
|
29
|
-
|
|
30
|
-
|
|
34
|
+
path = zip_path || "#{output_dir}.zip"
|
|
35
|
+
Zip::File.open(path, Zip::File::CREATE) do |zipfile|
|
|
36
|
+
Dir.glob("#{output_dir}/**/*").each do |file|
|
|
37
|
+
next if File.directory?(file)
|
|
31
38
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
39
|
+
entry_name = file.sub("#{File.dirname(output_dir)}/", "")
|
|
40
|
+
zipfile.add(entry_name, file)
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
path
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
private
|
|
47
|
+
|
|
48
|
+
def enrich_documents
|
|
49
|
+
index.publications.map do |pub|
|
|
50
|
+
enrich_publication(pub)
|
|
36
51
|
rescue StandardError => e
|
|
37
52
|
warn " Skip #{pub.identifier}: #{e.message}"
|
|
38
53
|
pub.to_h
|
|
39
54
|
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def enrich_publication(pub)
|
|
58
|
+
rxl_file = pub.files.find { |f| f.format == "rxl" }
|
|
59
|
+
return pub.to_h unless rxl_file
|
|
40
60
|
|
|
61
|
+
rxl_path = File.join(output_dir, rxl_file.path)
|
|
62
|
+
return pub.to_h unless File.exist?(rxl_path)
|
|
63
|
+
|
|
64
|
+
bib = Relaton::Bib::Item.from_xml(File.read(rxl_path))
|
|
65
|
+
pub.to_h.merge("bibliographic" => bib.to_h)
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
def write_relaton_index(documents)
|
|
41
69
|
dest = File.join(output_dir, "relaton")
|
|
42
70
|
FileUtils.mkdir_p(dest)
|
|
43
71
|
index_data = { "root" => { "title" => "Document Registry",
|
|
@@ -47,19 +75,59 @@ module Metanorma
|
|
|
47
75
|
File.write(File.join(dest, "index.yaml"), YAML.dump(index_data))
|
|
48
76
|
end
|
|
49
77
|
|
|
50
|
-
def
|
|
51
|
-
|
|
78
|
+
def write_data_file(documents)
|
|
79
|
+
FileUtils.mkdir_p(@data_dir)
|
|
80
|
+
items = documents.compact.map { |doc| flatten_for_site(doc) }
|
|
81
|
+
File.write(File.join(@data_dir, "documents.json"),
|
|
82
|
+
JSON.pretty_generate({ "items" => items }))
|
|
83
|
+
end
|
|
52
84
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
85
|
+
def flatten_for_site(doc)
|
|
86
|
+
bib = doc["bibliographic"] || {}
|
|
87
|
+
doc_id = resolve_doc_id(bib, doc)
|
|
88
|
+
{
|
|
89
|
+
"slug" => doc["id"],
|
|
90
|
+
"id" => doc_id,
|
|
91
|
+
"title" => doc["title"].to_s,
|
|
92
|
+
"abstract" => extract_abstract(bib),
|
|
93
|
+
"stage" => (doc["stage"] || "published").to_s.downcase,
|
|
94
|
+
"doctype" => extract_doctype(bib) || doc.fetch("doctype", ""),
|
|
95
|
+
"edition" => doc["edition"],
|
|
96
|
+
"date" => extract_date(doc),
|
|
97
|
+
"channels" => doc["channels"] || [],
|
|
98
|
+
"formats" => doc["formats"] || [],
|
|
99
|
+
"files" => doc["files"] || [],
|
|
100
|
+
}
|
|
101
|
+
end
|
|
57
102
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
103
|
+
def resolve_doc_id(bib, doc)
|
|
104
|
+
extract_primary_id(bib) || doc["identifier"] || doc["id"]
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
def extract_primary_id(bib)
|
|
108
|
+
ids = bib["docidentifier"]
|
|
109
|
+
return nil unless ids&.any?
|
|
110
|
+
|
|
111
|
+
primary = ids.find { |di| di["primary"] == true } || ids.first
|
|
112
|
+
primary["content"]
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
def extract_doctype(bib)
|
|
116
|
+
bib.dig("ext", "doctype", "content")
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
def extract_abstract(bib)
|
|
120
|
+
abstracts = bib["abstract"]
|
|
121
|
+
return nil unless abstracts&.any?
|
|
122
|
+
|
|
123
|
+
abstracts.first["content"]
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
def extract_date(doc)
|
|
127
|
+
release_date = doc.dig("source", "releaseDate")
|
|
128
|
+
return nil unless release_date
|
|
129
|
+
|
|
130
|
+
release_date.to_s.split(/[T ]/).first
|
|
63
131
|
end
|
|
64
132
|
end
|
|
65
133
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: metanorma-release
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.
|
|
4
|
+
version: 0.2.6
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ribose Inc.
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-05-
|
|
11
|
+
date: 2026-05-18 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: relaton-bib
|