k.site
Versioned resource access, site context, and site-level management for the current site
| Execution Context | Prerequisites | Typical Use |
|---|---|---|
| KScript API / KView / Server scripts | Current site context (list, isNameExists, get, 2-arg createSite, and xCopy enforce user/org checks; 3-arg createSite and exportSite require explicit script auth) | Read and write pages, layouts, views, scripts, styles, files, images, and site context |
Quick Start
Read the current site's name, default home URL, disk space usage, and page count:
k.api.get("siteOverview", () => {
return {
name: k.site.webSite.name,
homeUrl: k.site.getHomeUrl(),
diskSpace: k.site.diskSpace.getSiteSize(),
pageCount: k.site.pages.all().length
}
})Difference from k.file
- k.site: Versioned, routable site resources stored in the site database (pages, layouts, views, scripts, styles, code items, and the CMS file library
k.site.files). - k.file: Direct file operations on the site's disk directory (no dedicated CMS file-library UI); see k.file.
Quick Reference
| Method / Property | Description | Returns |
|---|---|---|
k.site.pages / layouts / views | Page, layout skeleton, and view fragment repositories (see page.md, layout.md, view.md) | PageRepository / LayoutRepository / ViewRepository |
k.site.scripts / styles / codes | Standalone JS, CSS, and Code repositories (see js.md, css.md, code.md) | ScriptRepository / StyleRepository / CodeRepository |
k.site.files / images | CMS file library and site image media repository (see file.md, image.md) | FileRepository / ImageRepository |
k.site.menus / htmlBlocks / formValues / routes | Navigation menus, HTML blocks, form records, and routes (see menu.md, html-block.md, form-value.md, route.md) | Repository objects |
k.site.job / runJob(name) / getJob(name) | Scheduled job management, manual trigger, and status queries (see job.md) | JobRepository / void / SiteJobStatus |
k.site.info / webSite / settings / multilingual / search / version / diskSpace / helper | Site metadata, settings, multilingual URLs, and full-text search (see context.md) | Context helper objects |
k.site.labels / k.site.editLog | Multilingual label repository (k.label) and edit history (k.history) | LabelRepository / KEditLog |
list() | Lists accessible sites for the current logged-in user (returns null anonymously) | SiteSummaryViewModel[] | null |
getHomeUrl() | Gets the full base URL of the current site's default start page | string | null |
isDomainExists(name) | Checks whether a shared or bound domain is already in use | boolean |
isNameExists(siteName) | Checks whether a site name exists in the current organization (auth required) | boolean |
Core Submodules
| Member | Doc | Description |
|---|---|---|
k.site.pages | page.md | Site pages, routes, and version logs |
k.site.layouts | layout.md | Layout skeletons and placeholder containers |
k.site.views | view.md | Reusable view fragments |
k.site.scripts | js.md | Standalone JavaScript resources |
k.site.styles | css.md | Standalone CSS stylesheet resources |
k.site.codes | code.md | API scripts, CodeBlocks, and other code items |
k.site.menus | menu.md | Navigation menus and submenu trees |
k.site.job / runJob / getJob | job.md | Scheduled job CRUD, manual trigger, and status queries |
k.site.files | file.md | CMS file library resources (versioned routable files) |
k.site.images | image.md | Site image library and media storage upload |
k.site.htmlBlocks | html-block.md | Multilingual reusable HTML blocks |
k.site.formValues | form-value.md | Submitted form value records and version logs |
k.site.routes | route.md | Route lookup, remapping, and aliases |
k.site.labels | k.label | Multilingual labels (same store as k.label / k.t, with repository CRUD) |
k.site.editLog | k.history | Site edit history, diff, and rollback (equivalent to k.history) |
k.site.info / webSite / settings / multilingual / search / version / diskSpace / helper | context.md | Site metadata, settings, multilingual URLs, full-text search, asset versioning, and disk usage |
Common Root Methods
list()
Lists site summaries accessible to the current logged-in user. This method requires an authenticated user and organization context; in an anonymous HTTP API request it returns null.
None
Returns: SiteSummaryViewModel[] | null
k.api.get("sites", () => {
const sites = k.site.list()
if (!sites) {
return { isNull: true, sites: [] }
}
return {
count: sites.length,
sites: sites.map((s) => ({
siteId: s.siteId,
siteName: s.siteName,
siteDisplayName: s.siteDisplayName,
online: s.online
}))
}
})getHomeUrl()
Returns the base URL of the current site's default start page, or null when no default start route is configured.
None
Returns: string | null
k.api.get("homeUrl", () => {
return { homeUrl: k.site.getHomeUrl() }
})isDomainExists() / isNameExists()
Checks whether a domain binding or a site name in the current organization is already taken.
| Method | Parameter | Returns | Description |
|---|---|---|---|
isDomainExists(name) | name: string | boolean | Checks whether a domain (shared staging domain or bound host) is already in use |
isNameExists(siteName) | siteName: string | boolean | Checks whether a site name exists in the current organization; requires an authenticated user and organization context (throws a null-reference error when called anonymously) |
Returns: boolean
k.api.get("domainCheck", () => {
return {
exists: k.site.isDomainExists("example.localkooboo.com")
}
})Admin & Specialized Capabilities
Beyond day-to-day site development repositories and context helpers, k.site exposes privileged cross-site provisioning, export, and publish-sync root methods. Not all of them perform built-in user authentication checks—restrict them to controlled administrative endpoints and enforce authorization explicitly:
| Category | Members | Notes |
|---|---|---|
| Built-in user check | get(siteName), createSite(siteName, fullDomain) | Enforces context.User; calling anonymously throws "user or website not valid" |
| Cross-site fast clone | xCopy(sourceSiteNameOrId, siteName, fullDomain, published) | Enforces context.User and organization access; when anonymous, redirects to the login page and returns null |
| No built-in user check (privileged) | createSite(siteName, fullDomain, binary), exportSite(nameOrId, copyMode, path) | Uses only the current site's OrganizationId and does not check context.User, so they can execute in anonymous requests; scripts must enforce user authentication and authorization explicitly before calling them |
| Collaboration & sync helpers | createPublishUser(siteUrl, role, expire), importPublishUser(siteUrl, bearer), enableCodeVideoLog(siteUrl) | Forwards the current request's Cookie/Authorization headers to generate/import remote publish user tokens and enable code video logging |
Quick Context Example
Read basic site metadata and disk usage (see context.md for full context properties):
k.api.get("siteSize", () => {
return {
name: k.site.webSite.name,
diskSpace: k.site.diskSpace.getSiteSize()
}
})TypeScript Definitions
Show full TypeScript definitions
type CopyMode = 'Normal' | 'Fast';
interface kSiteDb {
version: FileVersion;
info: InfoModel;
webSite: WebSiteInspection;
pages: PageRepository;
helper: SiteHelper;
editLog: KEditLog;
diskSpace: DiskSpace;
views: ViewRepository;
layouts: LayoutRepository;
htmlBlocks: HtmlBlockRepository;
labels: LabelRepository;
scripts: ScriptRepository;
codes: CodeRepository;
styles: StyleRepository;
images: ImageRepository;
files: FileRepository;
routes: RouteObjectRepository;
formValues: FormValuesRepository;
settings: kCoreSettings;
search: Search;
menus: KMenus;
multilingual: Multilingual;
job: JobRepository;
list(): SiteSummaryViewModel[];
isDomainExists(name: string): boolean;
isNameExists(SiteName: string): boolean;
get(SiteName: string): kSiteDb;
createSite(siteName: string, fullDomain: string): kSiteDb;
createSite(siteName: string, fullDomain: string, Binary: number[]): kSiteDb;
exportSite(nameOrId: string, copyMode: CopyMode, path: string): void;
xCopy(sourceSiteNameOrId: string, siteName: string, fullDomain: string, published: boolean): SitePackageResult;
createPublishUser(siteUrl: string, role: string, expire: number): string;
enableCodeVideoLog(siteUrl: string): string;
importPublishUser(siteUrl: string, bearer: string): void;
getHomeUrl(): string;
runJob(name: string): void;
getJob(name: string): SiteJobStatus;
}Related Docs
- Template Engine: Layout / Page / View — How HTML templates reference layouts and views
- k.page — Metadata for the currently rendering page (
k.page.setTitle, etc.) - k.module — Script module context
- k.label — Multilingual
k.t/k.label - k.history — Site edit history and rollback
- Admin: Files — CMS file library UI (
k.site.files, notk.file)