Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/origin/feature/11ty' into featu…
Browse files Browse the repository at this point in the history
…re/11ty-format

# Conflicts:
#	site/pages/Docs/Docs API/Additional API/index.md
#	site/pages/Docs/Docs API/Get Started/index.md
#	site/pages/Docs/Docs API/More Information/index.md
#	site/pages/Docs/Docs API/Usage API/index.md
#	site/pages/Docs/Docs API/Using WOPI/index.md
  • Loading branch information
LinneyS committed Jul 17, 2024
2 parents 30dea33 + c2625cb commit 7afded5
Show file tree
Hide file tree
Showing 90 changed files with 1,711 additions and 935 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
- name: Build Site
timeout-minutes: 60
working-directory: site
run: /usr/bin/time -l pnpm build
run: /usr/bin/time --verbose pnpm build

- name: Sync bucket
run: |
Expand Down
103 changes: 75 additions & 28 deletions packages/eleventy-sitemap/lib/main.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,87 @@
import {randomUUID} from "node:crypto"
import {extname} from "node:path"
import {type Data, type UserConfig} from "@onlyoffice/eleventy-types"
import {randomUUID} from "node:crypto"
import {isEmpty} from "@onlyoffice/objects"

declare module "@onlyoffice/eleventy-types" {
interface Data {
sitemap?(d: Data): SitemapData
sitemap?: SitemapData
}

interface EleventyComputed {
sitemap?(data: Data): SitemapData | undefined
}
}

export interface SitemapData {
title?: string
url?: string
path?: string
order?: number
groups?(): {
title: string
url: string
path: string
order: number
groups: {
title?: string
order?: number
}[]
group?(): string
data?: Data
group: string
data: Data
}

export class SitemapDatum implements SitemapData {
title = ""
url = ""
path = ""
order = 0
groups: SitemapData["groups"] = []
group = ""
data: SitemapData["data"] = {}

static merge(a: SitemapData, b: SitemapData): SitemapData {
const c = new SitemapDatum()

if (b.title) {
c.title = b.title
} else if (a.title) {
c.title = a.title
}

if (b.url) {
c.url = b.url
} else if (a.url) {
c.url = a.url
}

if (b.path) {
c.path = b.path
} else if (a.path) {
c.path = a.path
}

if (b.order) {
c.order = b.order
} else if (a.order) {
c.order = a.order
}

if (b.groups.length !== 0) {
c.groups = b.groups
} else if (a.groups.length !== 0) {
c.groups = a.groups
}

if (b.group) {
c.group = b.group
} else if (a.group) {
c.group = a.group
}

if (!isEmpty(b.data)) {
c.data = b.data
} else if (!isEmpty(a.data)) {
c.data = a.data
}

return c
}
}

export interface SitemapAccessible {
Expand Down Expand Up @@ -105,24 +168,11 @@ export function eleventySitemap(uc: UserConfig): void {
continue
}

const d = te.data.sitemap(te.data)
const d = te.data.sitemap
if (!d) {
continue
}

if (!d.title) {
throw new Error("No title")
}
if (!d.url) {
throw new Error("No URL")
}
if (!d.path) {
throw new Error("No path")
}
if (!d.data) {
throw new Error("No data")
}

const p = new SitemapPage()
p.id = randomUUID()
p.title = d.title
Expand Down Expand Up @@ -155,7 +205,7 @@ export function eleventySitemap(uc: UserConfig): void {
}

if (d.groups) {
const a = d.groups()
const a = d.groups
for (const d of a) {
if (!d.title) {
throw new Error("No title")
Expand Down Expand Up @@ -185,10 +235,7 @@ export function eleventySitemap(uc: UserConfig): void {
}

if (d.group) {
const n = d.group()
if (n) {
c.set(p.id, n)
}
c.set(p.id, d.group)
}
}

Expand Down
1 change: 1 addition & 0 deletions packages/eleventy-sitemap/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
},
"dependencies": {
"@onlyoffice/eleventy-types": "workspace:^",
"@onlyoffice/objects": "workspace:^",
"typescript": "^5.4.5"
}
}
9 changes: 8 additions & 1 deletion packages/eleventy-types/lib/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,8 @@ export interface Data {
* {@link https://www.11ty.dev/docs/pagination/ Eleventy Reference}
*/
export interface Pagination {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
items?: any[]
data?: string
size?: number
addAllPagesToCollections?: boolean
Expand All @@ -183,6 +185,11 @@ export interface Pagination {
*/
export interface EleventyComputed {
[k: string]: unknown

/**
* {@link https://www.11ty.dev/docs/layouts/ Eleventy Reference}
*/
layout?(data: Data): string | undefined
}

/**
Expand All @@ -207,7 +214,7 @@ export interface Page {
/**
* {@link https://www.11ty.dev/docs/data-eleventy-supplied/ Eleventy Reference}
*/
export interface Context {
export interface Context extends Data {
collections: Collections
content: Content
eleventy: Eleventy
Expand Down
52 changes: 52 additions & 0 deletions packages/objects/lib/main.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import {is} from "uvu/assert"
import {test} from "uvu"
import {isEmpty} from "./main.ts"

test("isEmpty(): returns false for a string", () => {
const a = isEmpty("")
is(a, false)
})

test("isEmpty(): returns false for a number", () => {
const a = isEmpty(0)
is(a, false)
})

test("isEmpty(): returns false for an arrow function", () => {
const a = isEmpty(() => {})
is(a, false)
})

test("isEmpty(): returns false for a function", () => {
// eslint-disable-next-line prefer-arrow-callback
const a = isEmpty(function () {})
is(a, false)
})

test("isEmpty(): returns false for a boolean", () => {
const a = isEmpty(false)
is(a, false)
})

test("isEmpty(): returns false for a null", () => {
const a = isEmpty(null)
is(a, false)
})

test("isEmpty(): returns false for an undefined", () => {
// eslint-disable-next-line unicorn/no-useless-undefined
const a = isEmpty(undefined)
is(a, false)
})

test("isEmpty(): returns true for an empty object", () => {
const a = isEmpty({})
is(a, true)
})

test("isEmpty(): returns false for an object with properties", () => {
const a = isEmpty({a: 1})
is(a, false)
})

test.run()
26 changes: 26 additions & 0 deletions packages/objects/lib/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
export function isEmpty(o: unknown): boolean {
if (!isPlain(o)) {
return false
}

for (const k in o) {
if (Object.hasOwn(o, k)) {
return false
}
}

return true
}

export function isPlain(o: unknown): o is object {
if (!o || typeof o !== "object") {
return false
}

const p = Object.getPrototypeOf(o)
if (!p && p !== Object.prototype) {
return false
}

return true
}
19 changes: 19 additions & 0 deletions packages/objects/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "@onlyoffice/objects",
"private": true,
"type": "module",
"main": "lib/main.ts",
"scripts": {
"test:types": "tsc",
"test:unit": "c8 --config ../../c8.config.json tsx node_modules/uvu/bin.js lib ^.*\\.test\\.ts$",
"test": "pnpm test:types && pnpm test:unit"
},
"dependencies": {
"typescript": "^5.4.5"
},
"devDependencies": {
"c8": "^9.1.0",
"tsx": "^4.10.5",
"uvu": "^0.5.6"
}
}
4 changes: 4 additions & 0 deletions packages/objects/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "../../tsconfig.base.json",
"include": ["lib"]
}
41 changes: 14 additions & 27 deletions packages/site-config/lib/main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {existsSync, readFileSync} from "node:fs"
import {join} from "node:path"
import {cwd} from "node:process"
import {type DocEditorConfigEvents, type DocEditorConfigurableOptions} from "@onlyoffice/document-server-types"
import yaml from "yaml"

Expand All @@ -17,23 +16,13 @@ export interface Configurable {
}

export class Config implements Configurable {
static shared: Configurable

baseUrl = ""
server = new ServerConfig()
playground = new PlaygroundConfig()

static #config: Configurable
static #done = false

static read(m?: string): Configurable {
if (this.#done) {
return this.#config
}
this.#done = true
this.#config = this.load(cwd(), m)
return this.#config
}

static load(d: string, m?: string): Configurable {
static read(d: string, m?: string): Configurable {
// It is crucial to use synchronous operations. This will allow
// configuration to be loaded within the Eleventy or JSX components.

Expand Down Expand Up @@ -107,12 +96,10 @@ export class Config implements Configurable {
static merge(a: Configurable, b: Configurable): Configurable {
const co = new Config()

if (a.baseUrl && b.baseUrl) {
if (b.baseUrl) {
co.baseUrl = b.baseUrl
} else if (a.baseUrl) {
co.baseUrl = a.baseUrl
} else if (b.baseUrl) {
co.baseUrl = b.baseUrl
}

co.server = ServerConfig.merge(a.server, b.server)
Expand Down Expand Up @@ -160,12 +147,10 @@ export class ServerConfig implements ServerConfigurable {
): ServerConfigurable {
const s = new ServerConfig()

if (a.baseUrl && b.baseUrl) {
if (b.baseUrl) {
s.baseUrl = b.baseUrl
} else if (a.baseUrl) {
s.baseUrl = a.baseUrl
} else if (b.baseUrl) {
s.baseUrl = b.baseUrl
}

return s
Expand Down Expand Up @@ -278,28 +263,26 @@ export class DocumentEditorConfig implements DocumentEditorConfigurable {
): DocumentEditorConfigurable {
const de = new DocumentEditorConfig()

if (a.documentServerUrl && b.documentServerUrl) {
if (b.documentServerUrl) {
de.documentServerUrl = b.documentServerUrl
} else if (a.documentServerUrl) {
de.documentServerUrl = a.documentServerUrl
} else if (b.documentServerUrl) {
de.documentServerUrl = b.documentServerUrl
}

if (a.config.length !== 0 && b.config.length !== 0) {
throw new Error("Merging of config is not supported")
} else if (a.config.length !== 0) {
de.config = a.config
} else if (b.config.length !== 0) {
de.config = b.config
} else if (a.config.length !== 0) {
de.config = a.config
}

if (a.scenarios.length !== 0 && b.scenarios.length !== 0) {
throw new Error("Merging of scenarios is not supported")
} else if (a.scenarios.length !== 0) {
de.scenarios = a.scenarios
} else if (b.scenarios.length !== 0) {
de.scenarios = b.scenarios
} else if (a.scenarios.length !== 0) {
de.scenarios = a.scenarios
}

return de
Expand Down Expand Up @@ -494,3 +477,7 @@ interface InputScenarioConfig extends DocEditorConfigurableOptions {
}

type ScenarioConfigurable = InputScenario

if (!Config.shared) {
Config.shared = new Config()
}
Loading

0 comments on commit 7afded5

Please sign in to comment.