@digitalculture/ochre-sdk 0.4.2 → 0.4.4
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.
- package/dist/index.cjs +55 -20
- package/dist/index.js +55 -20
- package/package.json +4 -3
package/dist/index.cjs
CHANGED
|
@@ -77,6 +77,7 @@ __export(index_exports, {
|
|
|
77
77
|
module.exports = __toCommonJS(index_exports);
|
|
78
78
|
|
|
79
79
|
// src/utils/parse.ts
|
|
80
|
+
var import_uuid = require("uuid");
|
|
80
81
|
var import_zod3 = require("zod");
|
|
81
82
|
|
|
82
83
|
// src/utils/fetchers/generic.ts
|
|
@@ -198,11 +199,13 @@ function parseWhitespace(contentString, whitespace) {
|
|
|
198
199
|
console.warn(`Invalid whitespace string provided: \u201C${whitespace}\u201D`);
|
|
199
200
|
return contentString;
|
|
200
201
|
}
|
|
201
|
-
for (const option of result.data) {
|
|
202
|
+
for (const [index, option] of result.data.entries()) {
|
|
202
203
|
switch (option) {
|
|
203
204
|
case "newline": {
|
|
204
|
-
|
|
205
|
-
|
|
205
|
+
if (index !== 0) {
|
|
206
|
+
returnString = `<br />
|
|
207
|
+
${returnString}`;
|
|
208
|
+
}
|
|
206
209
|
break;
|
|
207
210
|
}
|
|
208
211
|
case "trailing": {
|
|
@@ -1904,7 +1907,7 @@ async function parseWebpage(webpageResource) {
|
|
|
1904
1907
|
return null;
|
|
1905
1908
|
}
|
|
1906
1909
|
const identification = parseIdentification(webpageResource.identification);
|
|
1907
|
-
const slug = webpageResource.slug
|
|
1910
|
+
const slug = webpageResource.slug;
|
|
1908
1911
|
if (slug === void 0) {
|
|
1909
1912
|
throw new Error(`Slug not found for page \u201C${identification.label}\u201D`);
|
|
1910
1913
|
}
|
|
@@ -1914,16 +1917,55 @@ async function parseWebpage(webpageResource) {
|
|
|
1914
1917
|
const imageLink = links.find(
|
|
1915
1918
|
(link) => link.type === "image" || link.type === "IIIF"
|
|
1916
1919
|
);
|
|
1917
|
-
const
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
)
|
|
1921
|
-
|
|
1922
|
-
|
|
1923
|
-
|
|
1920
|
+
const webpageResources = webpageResource.resource ? Array.isArray(webpageResource.resource) ? webpageResource.resource : [webpageResource.resource] : [];
|
|
1921
|
+
const blocks = [];
|
|
1922
|
+
let elementsToHandle = [];
|
|
1923
|
+
for (const resource of webpageResources) {
|
|
1924
|
+
const resourceProperties = resource.properties ? parseProperties(
|
|
1925
|
+
Array.isArray(resource.properties.property) ? resource.properties.property : [resource.properties.property]
|
|
1926
|
+
) : [];
|
|
1927
|
+
const resourceType = getPropertyValueByLabel(
|
|
1928
|
+
resourceProperties,
|
|
1929
|
+
"presentation"
|
|
1930
|
+
);
|
|
1931
|
+
if (!resourceType) {
|
|
1932
|
+
continue;
|
|
1933
|
+
}
|
|
1934
|
+
if (resourceType !== "block") {
|
|
1935
|
+
elementsToHandle.push(resource);
|
|
1936
|
+
} else {
|
|
1937
|
+
if (elementsToHandle.length > 0) {
|
|
1938
|
+
const elements = await parseWebpageResources(
|
|
1939
|
+
elementsToHandle,
|
|
1940
|
+
"element"
|
|
1941
|
+
);
|
|
1942
|
+
const block = {
|
|
1943
|
+
uuid: (0, import_uuid.v4)(),
|
|
1944
|
+
layout: "vertical",
|
|
1945
|
+
blocks: [],
|
|
1946
|
+
elements,
|
|
1947
|
+
properties: {
|
|
1948
|
+
spacing: "auto",
|
|
1949
|
+
gap: "none",
|
|
1950
|
+
alignItems: "stretch",
|
|
1951
|
+
justifyContent: "stretch"
|
|
1952
|
+
},
|
|
1953
|
+
cssStyles: []
|
|
1954
|
+
};
|
|
1955
|
+
blocks.push(block);
|
|
1956
|
+
elementsToHandle = [];
|
|
1957
|
+
}
|
|
1958
|
+
const parsedBlocks = await parseWebpageResources([resource], "block");
|
|
1959
|
+
blocks.push(...parsedBlocks);
|
|
1960
|
+
}
|
|
1961
|
+
}
|
|
1962
|
+
if (elementsToHandle.length > 0) {
|
|
1963
|
+
const elements = await parseWebpageResources(elementsToHandle, "element");
|
|
1964
|
+
const block = {
|
|
1965
|
+
uuid: (0, import_uuid.v4)(),
|
|
1924
1966
|
layout: "vertical",
|
|
1925
1967
|
blocks: [],
|
|
1926
|
-
elements
|
|
1968
|
+
elements,
|
|
1927
1969
|
properties: {
|
|
1928
1970
|
spacing: "auto",
|
|
1929
1971
|
gap: "none",
|
|
@@ -1932,14 +1974,7 @@ async function parseWebpage(webpageResource) {
|
|
|
1932
1974
|
},
|
|
1933
1975
|
cssStyles: []
|
|
1934
1976
|
};
|
|
1935
|
-
blocks.push(
|
|
1936
|
-
const elements = webpageResource.resource ? await parseWebpageResources(
|
|
1937
|
-
Array.isArray(webpageResource.resource) ? webpageResource.resource : [webpageResource.resource],
|
|
1938
|
-
"element"
|
|
1939
|
-
) : [];
|
|
1940
|
-
if (elements.length > 0) {
|
|
1941
|
-
defaultBlock.elements = elements;
|
|
1942
|
-
}
|
|
1977
|
+
blocks.push(block);
|
|
1943
1978
|
}
|
|
1944
1979
|
const webpages = webpageResource.resource ? await parseWebpageResources(
|
|
1945
1980
|
Array.isArray(webpageResource.resource) ? webpageResource.resource : [webpageResource.resource],
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// src/utils/parse.ts
|
|
2
|
+
import { v4 as uuidv4 } from "uuid";
|
|
2
3
|
import { z as z3 } from "zod";
|
|
3
4
|
|
|
4
5
|
// src/utils/fetchers/generic.ts
|
|
@@ -120,11 +121,13 @@ function parseWhitespace(contentString, whitespace) {
|
|
|
120
121
|
console.warn(`Invalid whitespace string provided: \u201C${whitespace}\u201D`);
|
|
121
122
|
return contentString;
|
|
122
123
|
}
|
|
123
|
-
for (const option of result.data) {
|
|
124
|
+
for (const [index, option] of result.data.entries()) {
|
|
124
125
|
switch (option) {
|
|
125
126
|
case "newline": {
|
|
126
|
-
|
|
127
|
-
|
|
127
|
+
if (index !== 0) {
|
|
128
|
+
returnString = `<br />
|
|
129
|
+
${returnString}`;
|
|
130
|
+
}
|
|
128
131
|
break;
|
|
129
132
|
}
|
|
130
133
|
case "trailing": {
|
|
@@ -1826,7 +1829,7 @@ async function parseWebpage(webpageResource) {
|
|
|
1826
1829
|
return null;
|
|
1827
1830
|
}
|
|
1828
1831
|
const identification = parseIdentification(webpageResource.identification);
|
|
1829
|
-
const slug = webpageResource.slug
|
|
1832
|
+
const slug = webpageResource.slug;
|
|
1830
1833
|
if (slug === void 0) {
|
|
1831
1834
|
throw new Error(`Slug not found for page \u201C${identification.label}\u201D`);
|
|
1832
1835
|
}
|
|
@@ -1836,16 +1839,55 @@ async function parseWebpage(webpageResource) {
|
|
|
1836
1839
|
const imageLink = links.find(
|
|
1837
1840
|
(link) => link.type === "image" || link.type === "IIIF"
|
|
1838
1841
|
);
|
|
1839
|
-
const
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
)
|
|
1843
|
-
|
|
1844
|
-
|
|
1845
|
-
|
|
1842
|
+
const webpageResources = webpageResource.resource ? Array.isArray(webpageResource.resource) ? webpageResource.resource : [webpageResource.resource] : [];
|
|
1843
|
+
const blocks = [];
|
|
1844
|
+
let elementsToHandle = [];
|
|
1845
|
+
for (const resource of webpageResources) {
|
|
1846
|
+
const resourceProperties = resource.properties ? parseProperties(
|
|
1847
|
+
Array.isArray(resource.properties.property) ? resource.properties.property : [resource.properties.property]
|
|
1848
|
+
) : [];
|
|
1849
|
+
const resourceType = getPropertyValueByLabel(
|
|
1850
|
+
resourceProperties,
|
|
1851
|
+
"presentation"
|
|
1852
|
+
);
|
|
1853
|
+
if (!resourceType) {
|
|
1854
|
+
continue;
|
|
1855
|
+
}
|
|
1856
|
+
if (resourceType !== "block") {
|
|
1857
|
+
elementsToHandle.push(resource);
|
|
1858
|
+
} else {
|
|
1859
|
+
if (elementsToHandle.length > 0) {
|
|
1860
|
+
const elements = await parseWebpageResources(
|
|
1861
|
+
elementsToHandle,
|
|
1862
|
+
"element"
|
|
1863
|
+
);
|
|
1864
|
+
const block = {
|
|
1865
|
+
uuid: uuidv4(),
|
|
1866
|
+
layout: "vertical",
|
|
1867
|
+
blocks: [],
|
|
1868
|
+
elements,
|
|
1869
|
+
properties: {
|
|
1870
|
+
spacing: "auto",
|
|
1871
|
+
gap: "none",
|
|
1872
|
+
alignItems: "stretch",
|
|
1873
|
+
justifyContent: "stretch"
|
|
1874
|
+
},
|
|
1875
|
+
cssStyles: []
|
|
1876
|
+
};
|
|
1877
|
+
blocks.push(block);
|
|
1878
|
+
elementsToHandle = [];
|
|
1879
|
+
}
|
|
1880
|
+
const parsedBlocks = await parseWebpageResources([resource], "block");
|
|
1881
|
+
blocks.push(...parsedBlocks);
|
|
1882
|
+
}
|
|
1883
|
+
}
|
|
1884
|
+
if (elementsToHandle.length > 0) {
|
|
1885
|
+
const elements = await parseWebpageResources(elementsToHandle, "element");
|
|
1886
|
+
const block = {
|
|
1887
|
+
uuid: uuidv4(),
|
|
1846
1888
|
layout: "vertical",
|
|
1847
1889
|
blocks: [],
|
|
1848
|
-
elements
|
|
1890
|
+
elements,
|
|
1849
1891
|
properties: {
|
|
1850
1892
|
spacing: "auto",
|
|
1851
1893
|
gap: "none",
|
|
@@ -1854,14 +1896,7 @@ async function parseWebpage(webpageResource) {
|
|
|
1854
1896
|
},
|
|
1855
1897
|
cssStyles: []
|
|
1856
1898
|
};
|
|
1857
|
-
blocks.push(
|
|
1858
|
-
const elements = webpageResource.resource ? await parseWebpageResources(
|
|
1859
|
-
Array.isArray(webpageResource.resource) ? webpageResource.resource : [webpageResource.resource],
|
|
1860
|
-
"element"
|
|
1861
|
-
) : [];
|
|
1862
|
-
if (elements.length > 0) {
|
|
1863
|
-
defaultBlock.elements = elements;
|
|
1864
|
-
}
|
|
1899
|
+
blocks.push(block);
|
|
1865
1900
|
}
|
|
1866
1901
|
const webpages = webpageResource.resource ? await parseWebpageResources(
|
|
1867
1902
|
Array.isArray(webpageResource.resource) ? webpageResource.resource : [webpageResource.resource],
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@digitalculture/ochre-sdk",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "Node.js library for working with OCHRE (Online Cultural and Historical Research Environment) data",
|
|
@@ -41,6 +41,7 @@
|
|
|
41
41
|
],
|
|
42
42
|
"dependencies": {
|
|
43
43
|
"iso-639-3": "^3.0.1",
|
|
44
|
+
"uuid": "^11.1.0",
|
|
44
45
|
"zod": "^3.24.2"
|
|
45
46
|
},
|
|
46
47
|
"devDependencies": {
|
|
@@ -52,9 +53,9 @@
|
|
|
52
53
|
"eslint": "^9.21.0",
|
|
53
54
|
"eslint-plugin-unused-imports": "^4.1.4",
|
|
54
55
|
"prettier": "^3.5.2",
|
|
55
|
-
"tsup": "^8.
|
|
56
|
+
"tsup": "^8.4.0",
|
|
56
57
|
"typescript": "^5.7.3",
|
|
57
|
-
"vitest": "^3.0.
|
|
58
|
+
"vitest": "^3.0.7"
|
|
58
59
|
},
|
|
59
60
|
"scripts": {
|
|
60
61
|
"dev": "tsup src/index.ts --watch",
|