@digitalculture/ochre-sdk 0.4.2 → 0.4.3

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 CHANGED
@@ -198,11 +198,13 @@ function parseWhitespace(contentString, whitespace) {
198
198
  console.warn(`Invalid whitespace string provided: \u201C${whitespace}\u201D`);
199
199
  return contentString;
200
200
  }
201
- for (const option of result.data) {
201
+ for (const [index, option] of result.data.entries()) {
202
202
  switch (option) {
203
203
  case "newline": {
204
- returnString = `${returnString}
205
- <br />`;
204
+ if (index !== 0) {
205
+ returnString = `<br />
206
+ ${returnString}`;
207
+ }
206
208
  break;
207
209
  }
208
210
  case "trailing": {
@@ -1904,7 +1906,7 @@ async function parseWebpage(webpageResource) {
1904
1906
  return null;
1905
1907
  }
1906
1908
  const identification = parseIdentification(webpageResource.identification);
1907
- const slug = webpageResource.slug === "/" ? "" : webpageResource.slug;
1909
+ const slug = webpageResource.slug;
1908
1910
  if (slug === void 0) {
1909
1911
  throw new Error(`Slug not found for page \u201C${identification.label}\u201D`);
1910
1912
  }
@@ -1914,16 +1916,55 @@ async function parseWebpage(webpageResource) {
1914
1916
  const imageLink = links.find(
1915
1917
  (link) => link.type === "image" || link.type === "IIIF"
1916
1918
  );
1917
- const blocks = webpageResource.resource ? await parseWebpageResources(
1918
- Array.isArray(webpageResource.resource) ? webpageResource.resource : [webpageResource.resource],
1919
- "block"
1920
- ) : [];
1921
- if (blocks.length === 0) {
1922
- const defaultBlock = {
1919
+ const webpageResources = webpageResource.resource ? Array.isArray(webpageResource.resource) ? webpageResource.resource : [webpageResource.resource] : [];
1920
+ const blocks = [];
1921
+ let elementsToHandle = [];
1922
+ for (const resource of webpageResources) {
1923
+ const resourceProperties = resource.properties ? parseProperties(
1924
+ Array.isArray(resource.properties.property) ? resource.properties.property : [resource.properties.property]
1925
+ ) : [];
1926
+ const resourceType = getPropertyValueByLabel(
1927
+ resourceProperties,
1928
+ "presentation"
1929
+ );
1930
+ if (!resourceType) {
1931
+ continue;
1932
+ }
1933
+ if (resourceType !== "block") {
1934
+ elementsToHandle.push(resource);
1935
+ } else {
1936
+ if (elementsToHandle.length > 0) {
1937
+ const elements = await parseWebpageResources(
1938
+ elementsToHandle,
1939
+ "element"
1940
+ );
1941
+ const block = {
1942
+ uuid: resource.uuid,
1943
+ layout: "vertical",
1944
+ blocks: [],
1945
+ elements,
1946
+ properties: {
1947
+ spacing: "auto",
1948
+ gap: "none",
1949
+ alignItems: "stretch",
1950
+ justifyContent: "stretch"
1951
+ },
1952
+ cssStyles: []
1953
+ };
1954
+ blocks.push(block);
1955
+ elementsToHandle = [];
1956
+ }
1957
+ const parsedBlocks = await parseWebpageResources([resource], "block");
1958
+ blocks.push(...parsedBlocks);
1959
+ }
1960
+ }
1961
+ if (elementsToHandle.length > 0) {
1962
+ const elements = await parseWebpageResources(elementsToHandle, "element");
1963
+ const block = {
1923
1964
  uuid: webpageResource.uuid,
1924
1965
  layout: "vertical",
1925
1966
  blocks: [],
1926
- elements: [],
1967
+ elements,
1927
1968
  properties: {
1928
1969
  spacing: "auto",
1929
1970
  gap: "none",
@@ -1932,14 +1973,7 @@ async function parseWebpage(webpageResource) {
1932
1973
  },
1933
1974
  cssStyles: []
1934
1975
  };
1935
- blocks.push(defaultBlock);
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
- }
1976
+ blocks.push(block);
1943
1977
  }
1944
1978
  const webpages = webpageResource.resource ? await parseWebpageResources(
1945
1979
  Array.isArray(webpageResource.resource) ? webpageResource.resource : [webpageResource.resource],
package/dist/index.js CHANGED
@@ -120,11 +120,13 @@ function parseWhitespace(contentString, whitespace) {
120
120
  console.warn(`Invalid whitespace string provided: \u201C${whitespace}\u201D`);
121
121
  return contentString;
122
122
  }
123
- for (const option of result.data) {
123
+ for (const [index, option] of result.data.entries()) {
124
124
  switch (option) {
125
125
  case "newline": {
126
- returnString = `${returnString}
127
- <br />`;
126
+ if (index !== 0) {
127
+ returnString = `<br />
128
+ ${returnString}`;
129
+ }
128
130
  break;
129
131
  }
130
132
  case "trailing": {
@@ -1826,7 +1828,7 @@ async function parseWebpage(webpageResource) {
1826
1828
  return null;
1827
1829
  }
1828
1830
  const identification = parseIdentification(webpageResource.identification);
1829
- const slug = webpageResource.slug === "/" ? "" : webpageResource.slug;
1831
+ const slug = webpageResource.slug;
1830
1832
  if (slug === void 0) {
1831
1833
  throw new Error(`Slug not found for page \u201C${identification.label}\u201D`);
1832
1834
  }
@@ -1836,16 +1838,55 @@ async function parseWebpage(webpageResource) {
1836
1838
  const imageLink = links.find(
1837
1839
  (link) => link.type === "image" || link.type === "IIIF"
1838
1840
  );
1839
- const blocks = webpageResource.resource ? await parseWebpageResources(
1840
- Array.isArray(webpageResource.resource) ? webpageResource.resource : [webpageResource.resource],
1841
- "block"
1842
- ) : [];
1843
- if (blocks.length === 0) {
1844
- const defaultBlock = {
1841
+ const webpageResources = webpageResource.resource ? Array.isArray(webpageResource.resource) ? webpageResource.resource : [webpageResource.resource] : [];
1842
+ const blocks = [];
1843
+ let elementsToHandle = [];
1844
+ for (const resource of webpageResources) {
1845
+ const resourceProperties = resource.properties ? parseProperties(
1846
+ Array.isArray(resource.properties.property) ? resource.properties.property : [resource.properties.property]
1847
+ ) : [];
1848
+ const resourceType = getPropertyValueByLabel(
1849
+ resourceProperties,
1850
+ "presentation"
1851
+ );
1852
+ if (!resourceType) {
1853
+ continue;
1854
+ }
1855
+ if (resourceType !== "block") {
1856
+ elementsToHandle.push(resource);
1857
+ } else {
1858
+ if (elementsToHandle.length > 0) {
1859
+ const elements = await parseWebpageResources(
1860
+ elementsToHandle,
1861
+ "element"
1862
+ );
1863
+ const block = {
1864
+ uuid: resource.uuid,
1865
+ layout: "vertical",
1866
+ blocks: [],
1867
+ elements,
1868
+ properties: {
1869
+ spacing: "auto",
1870
+ gap: "none",
1871
+ alignItems: "stretch",
1872
+ justifyContent: "stretch"
1873
+ },
1874
+ cssStyles: []
1875
+ };
1876
+ blocks.push(block);
1877
+ elementsToHandle = [];
1878
+ }
1879
+ const parsedBlocks = await parseWebpageResources([resource], "block");
1880
+ blocks.push(...parsedBlocks);
1881
+ }
1882
+ }
1883
+ if (elementsToHandle.length > 0) {
1884
+ const elements = await parseWebpageResources(elementsToHandle, "element");
1885
+ const block = {
1845
1886
  uuid: webpageResource.uuid,
1846
1887
  layout: "vertical",
1847
1888
  blocks: [],
1848
- elements: [],
1889
+ elements,
1849
1890
  properties: {
1850
1891
  spacing: "auto",
1851
1892
  gap: "none",
@@ -1854,14 +1895,7 @@ async function parseWebpage(webpageResource) {
1854
1895
  },
1855
1896
  cssStyles: []
1856
1897
  };
1857
- blocks.push(defaultBlock);
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
- }
1898
+ blocks.push(block);
1865
1899
  }
1866
1900
  const webpages = webpageResource.resource ? await parseWebpageResources(
1867
1901
  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.2",
3
+ "version": "0.4.3",
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",
@@ -52,9 +52,9 @@
52
52
  "eslint": "^9.21.0",
53
53
  "eslint-plugin-unused-imports": "^4.1.4",
54
54
  "prettier": "^3.5.2",
55
- "tsup": "^8.3.6",
55
+ "tsup": "^8.4.0",
56
56
  "typescript": "^5.7.3",
57
- "vitest": "^3.0.6"
57
+ "vitest": "^3.0.7"
58
58
  },
59
59
  "scripts": {
60
60
  "dev": "tsup src/index.ts --watch",