mirror of
https://github.com/thiloho/archtika.git
synced 2025-11-22 10:51:36 +01:00
Ability to bulk import or export articles as gzip, handle domain prefix logic in API and other smaller improvements
This commit is contained in:
@@ -99,6 +99,14 @@
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
systemd.services.postgresql = {
|
||||||
|
path = with pkgs; [
|
||||||
|
# Tar and gzip are needed for tar.gz exports
|
||||||
|
gnutar
|
||||||
|
gzip
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
services.getty.autologinUser = "dev";
|
services.getty.autologinUser = "dev";
|
||||||
|
|
||||||
system.stateVersion = "24.05";
|
system.stateVersion = "24.05";
|
||||||
|
|||||||
@@ -169,6 +169,14 @@ in
|
|||||||
extraPlugins = with pkgs.postgresql16Packages; [ pgjwt ];
|
extraPlugins = with pkgs.postgresql16Packages; [ pgjwt ];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
systemd.services.postgresql = {
|
||||||
|
path = with pkgs; [
|
||||||
|
# Tar and gzip are needed for tar.gz exports
|
||||||
|
gnutar
|
||||||
|
gzip
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
services.nginx = {
|
services.nginx = {
|
||||||
enable = true;
|
enable = true;
|
||||||
recommendedProxySettings = true;
|
recommendedProxySettings = true;
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
-- migrate:up
|
-- migrate:up
|
||||||
|
CREATE EXTENSION unaccent;
|
||||||
|
|
||||||
CREATE SCHEMA internal;
|
CREATE SCHEMA internal;
|
||||||
|
|
||||||
CREATE SCHEMA api;
|
CREATE SCHEMA api;
|
||||||
@@ -27,6 +29,17 @@ GRANT USAGE ON SCHEMA internal TO authenticated_user;
|
|||||||
|
|
||||||
ALTER DEFAULT PRIVILEGES REVOKE EXECUTE ON FUNCTIONS FROM PUBLIC;
|
ALTER DEFAULT PRIVILEGES REVOKE EXECUTE ON FUNCTIONS FROM PUBLIC;
|
||||||
|
|
||||||
|
CREATE FUNCTION internal.immutable_unaccent (TEXT)
|
||||||
|
RETURNS TEXT
|
||||||
|
AS $$
|
||||||
|
SELECT
|
||||||
|
unaccent ($1);
|
||||||
|
$$
|
||||||
|
LANGUAGE sql
|
||||||
|
IMMUTABLE;
|
||||||
|
|
||||||
|
GRANT EXECUTE ON FUNCTION internal.immutable_unaccent TO authenticated_user;
|
||||||
|
|
||||||
CREATE TABLE internal.user (
|
CREATE TABLE internal.user (
|
||||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid (),
|
id UUID PRIMARY KEY DEFAULT gen_random_uuid (),
|
||||||
username VARCHAR(16) UNIQUE NOT NULL CHECK (LENGTH(username) >= 3 AND username ~ '^[a-zA-Z0-9_-]+$'),
|
username VARCHAR(16) UNIQUE NOT NULL CHECK (LENGTH(username) >= 3 AND username ~ '^[a-zA-Z0-9_-]+$'),
|
||||||
@@ -91,7 +104,7 @@ CREATE TABLE internal.docs_category (
|
|||||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid (),
|
id UUID PRIMARY KEY DEFAULT gen_random_uuid (),
|
||||||
website_id UUID REFERENCES internal.website (id) ON DELETE CASCADE NOT NULL,
|
website_id UUID REFERENCES internal.website (id) ON DELETE CASCADE NOT NULL,
|
||||||
user_id UUID REFERENCES internal.user (id) ON DELETE SET NULL DEFAULT (CURRENT_SETTING('request.jwt.claims', TRUE)::JSON ->> 'user_id') ::UUID,
|
user_id UUID REFERENCES internal.user (id) ON DELETE SET NULL DEFAULT (CURRENT_SETTING('request.jwt.claims', TRUE)::JSON ->> 'user_id') ::UUID,
|
||||||
category_name VARCHAR(50) NOT NULL CHECK (TRIM(category_name) != ''),
|
category_name VARCHAR(50) NOT NULL CHECK (TRIM(category_name) != '' AND category_name != 'Uncategorized'),
|
||||||
category_weight INT CHECK (category_weight >= 0) NOT NULL,
|
category_weight INT CHECK (category_weight >= 0) NOT NULL,
|
||||||
created_at TIMESTAMPTZ NOT NULL DEFAULT CLOCK_TIMESTAMP(),
|
created_at TIMESTAMPTZ NOT NULL DEFAULT CLOCK_TIMESTAMP(),
|
||||||
last_modified_at TIMESTAMPTZ NOT NULL DEFAULT CLOCK_TIMESTAMP(),
|
last_modified_at TIMESTAMPTZ NOT NULL DEFAULT CLOCK_TIMESTAMP(),
|
||||||
@@ -105,6 +118,7 @@ CREATE TABLE internal.article (
|
|||||||
website_id UUID REFERENCES internal.website (id) ON DELETE CASCADE NOT NULL,
|
website_id UUID REFERENCES internal.website (id) ON DELETE CASCADE NOT NULL,
|
||||||
user_id UUID REFERENCES internal.user (id) ON DELETE SET NULL DEFAULT (CURRENT_SETTING('request.jwt.claims', TRUE)::JSON ->> 'user_id') ::UUID,
|
user_id UUID REFERENCES internal.user (id) ON DELETE SET NULL DEFAULT (CURRENT_SETTING('request.jwt.claims', TRUE)::JSON ->> 'user_id') ::UUID,
|
||||||
title VARCHAR(100) NOT NULL CHECK (TRIM(title) != ''),
|
title VARCHAR(100) NOT NULL CHECK (TRIM(title) != ''),
|
||||||
|
slug VARCHAR(100) GENERATED ALWAYS AS (REGEXP_REPLACE(REGEXP_REPLACE(REGEXP_REPLACE(REGEXP_REPLACE(LOWER(TRIM(REGEXP_REPLACE(internal.immutable_unaccent (title), '\s+', '-', 'g'))), '[^\w-]', '', 'g'), '-+', '-', 'g'), '^-+', '', 'g'), '-+$', '', 'g')) STORED,
|
||||||
meta_description VARCHAR(250) CHECK (TRIM(meta_description) != ''),
|
meta_description VARCHAR(250) CHECK (TRIM(meta_description) != ''),
|
||||||
meta_author VARCHAR(100) CHECK (TRIM(meta_author) != ''),
|
meta_author VARCHAR(100) CHECK (TRIM(meta_author) != ''),
|
||||||
cover_image UUID REFERENCES internal.media (id) ON DELETE SET NULL,
|
cover_image UUID REFERENCES internal.media (id) ON DELETE SET NULL,
|
||||||
@@ -115,6 +129,7 @@ CREATE TABLE internal.article (
|
|||||||
created_at TIMESTAMPTZ NOT NULL DEFAULT CLOCK_TIMESTAMP(),
|
created_at TIMESTAMPTZ NOT NULL DEFAULT CLOCK_TIMESTAMP(),
|
||||||
last_modified_at TIMESTAMPTZ NOT NULL DEFAULT CLOCK_TIMESTAMP(),
|
last_modified_at TIMESTAMPTZ NOT NULL DEFAULT CLOCK_TIMESTAMP(),
|
||||||
last_modified_by UUID REFERENCES internal.user (id) ON DELETE SET NULL,
|
last_modified_by UUID REFERENCES internal.user (id) ON DELETE SET NULL,
|
||||||
|
UNIQUE (website_id, slug),
|
||||||
UNIQUE (website_id, category, article_weight)
|
UNIQUE (website_id, category, article_weight)
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -168,6 +183,8 @@ DROP TABLE internal.user;
|
|||||||
|
|
||||||
DROP SCHEMA api;
|
DROP SCHEMA api;
|
||||||
|
|
||||||
|
DROP FUNCTION internal.immutable_unaccent;
|
||||||
|
|
||||||
DROP SCHEMA internal;
|
DROP SCHEMA internal;
|
||||||
|
|
||||||
DROP ROLE anon;
|
DROP ROLE anon;
|
||||||
@@ -180,3 +197,5 @@ DROP ROLE authenticator;
|
|||||||
|
|
||||||
ALTER DEFAULT PRIVILEGES GRANT EXECUTE ON FUNCTIONS TO PUBLIC;
|
ALTER DEFAULT PRIVILEGES GRANT EXECUTE ON FUNCTIONS TO PUBLIC;
|
||||||
|
|
||||||
|
DROP EXTENSION unaccent;
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
-- migrate:up
|
-- migrate:up
|
||||||
CREATE DOMAIN "*/*" AS bytea;
|
CREATE DOMAIN "*/*" AS BYTEA;
|
||||||
|
|
||||||
CREATE FUNCTION api.upload_file (BYTEA, OUT file_id UUID)
|
CREATE FUNCTION api.upload_file (BYTEA, OUT file_id UUID)
|
||||||
AS $$
|
AS $$
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
-- migrate:up
|
-- migrate:up
|
||||||
CREATE TABLE internal.domain_prefix (
|
CREATE TABLE internal.domain_prefix (
|
||||||
website_id UUID PRIMARY KEY REFERENCES internal.website (id) ON DELETE CASCADE,
|
website_id UUID PRIMARY KEY REFERENCES internal.website (id) ON DELETE CASCADE,
|
||||||
prefix VARCHAR(16) UNIQUE NOT NULL CHECK (LENGTH(prefix) >= 3 AND prefix ~ '^[a-z]+(-[a-z]+)*$'),
|
prefix VARCHAR(16) UNIQUE NOT NULL CHECK (LENGTH(prefix) >= 3 AND prefix ~ '^[a-z]+(-[a-z]+)*$' AND prefix != 'previews'),
|
||||||
created_at TIMESTAMPTZ NOT NULL DEFAULT CLOCK_TIMESTAMP(),
|
created_at TIMESTAMPTZ NOT NULL DEFAULT CLOCK_TIMESTAMP(),
|
||||||
last_modified_at TIMESTAMPTZ NOT NULL DEFAULT CLOCK_TIMESTAMP(),
|
last_modified_at TIMESTAMPTZ NOT NULL DEFAULT CLOCK_TIMESTAMP(),
|
||||||
last_modified_by UUID REFERENCES internal.user (id) ON DELETE SET NULL
|
last_modified_by UUID REFERENCES internal.user (id) ON DELETE SET NULL
|
||||||
@@ -14,9 +14,9 @@ SELECT
|
|||||||
FROM
|
FROM
|
||||||
internal.domain_prefix;
|
internal.domain_prefix;
|
||||||
|
|
||||||
GRANT SELECT, INSERT (website_id, prefix), UPDATE (website_id, prefix), DELETE ON internal.domain_prefix TO authenticated_user;
|
GRANT SELECT ON internal.domain_prefix TO authenticated_user;
|
||||||
|
|
||||||
GRANT SELECT, INSERT, UPDATE, DELETE ON api.domain_prefix TO authenticated_user;
|
GRANT SELECT ON api.domain_prefix TO authenticated_user;
|
||||||
|
|
||||||
ALTER TABLE internal.domain_prefix ENABLE ROW LEVEL SECURITY;
|
ALTER TABLE internal.domain_prefix ENABLE ROW LEVEL SECURITY;
|
||||||
|
|
||||||
@@ -24,17 +24,64 @@ CREATE POLICY view_domain_prefix ON internal.domain_prefix
|
|||||||
FOR SELECT
|
FOR SELECT
|
||||||
USING (internal.user_has_website_access (website_id, 10));
|
USING (internal.user_has_website_access (website_id, 10));
|
||||||
|
|
||||||
CREATE POLICY update_domain_prefix ON internal.domain_prefix
|
CREATE FUNCTION api.set_domain_prefix (website_id UUID, prefix VARCHAR(16), OUT was_set BOOLEAN)
|
||||||
FOR UPDATE
|
AS $$
|
||||||
USING (internal.user_has_website_access (website_id, 30));
|
DECLARE
|
||||||
|
_has_access BOOLEAN;
|
||||||
|
_old_domain_prefix VARCHAR(16);
|
||||||
|
_base_path CONSTANT TEXT := '/var/www/archtika-websites/';
|
||||||
|
_old_path TEXT;
|
||||||
|
_new_path TEXT;
|
||||||
|
BEGIN
|
||||||
|
_has_access = internal.user_has_website_access (set_domain_prefix.website_id, 30);
|
||||||
|
SELECT
|
||||||
|
d.prefix INTO _old_domain_prefix
|
||||||
|
FROM
|
||||||
|
internal.domain_prefix AS d
|
||||||
|
WHERE
|
||||||
|
d.website_id = set_domain_prefix.website_id;
|
||||||
|
INSERT INTO internal.domain_prefix (website_id, prefix)
|
||||||
|
VALUES (set_domain_prefix.website_id, set_domain_prefix.prefix)
|
||||||
|
ON CONFLICT ON CONSTRAINT domain_prefix_pkey
|
||||||
|
DO UPDATE SET
|
||||||
|
prefix = EXCLUDED.prefix;
|
||||||
|
_old_path = _base_path || COALESCE(_old_domain_prefix, set_domain_prefix.website_id::TEXT);
|
||||||
|
_new_path = _base_path || set_domain_prefix.prefix;
|
||||||
|
IF _old_path != _new_path THEN
|
||||||
|
EXECUTE FORMAT('COPY (SELECT '''') TO PROGRAM ''mv -T %s %s''', _old_path, _new_path);
|
||||||
|
END IF;
|
||||||
|
was_set := TRUE;
|
||||||
|
END;
|
||||||
|
$$
|
||||||
|
LANGUAGE plpgsql
|
||||||
|
SECURITY DEFINER;
|
||||||
|
|
||||||
CREATE POLICY delete_domain_prefix ON internal.domain_prefix
|
GRANT EXECUTE ON FUNCTION api.set_domain_prefix TO authenticated_user;
|
||||||
FOR DELETE
|
|
||||||
USING (internal.user_has_website_access (website_id, 30));
|
|
||||||
|
|
||||||
CREATE POLICY insert_domain_prefix ON internal.domain_prefix
|
CREATE FUNCTION api.delete_domain_prefix (website_id UUID, OUT was_deleted BOOLEAN)
|
||||||
FOR INSERT
|
AS $$
|
||||||
WITH CHECK (internal.user_has_website_access (website_id, 30));
|
DECLARE
|
||||||
|
_has_access BOOLEAN;
|
||||||
|
_old_domain_prefix VARCHAR(16);
|
||||||
|
_base_path CONSTANT TEXT := '/var/www/archtika-websites/';
|
||||||
|
_old_path TEXT;
|
||||||
|
_new_path TEXT;
|
||||||
|
BEGIN
|
||||||
|
_has_access = internal.user_has_website_access (delete_domain_prefix.website_id, 30);
|
||||||
|
DELETE FROM internal.domain_prefix AS d
|
||||||
|
WHERE d.website_id = delete_domain_prefix.website_id
|
||||||
|
RETURNING
|
||||||
|
prefix INTO _old_domain_prefix;
|
||||||
|
_old_path = _base_path || _old_domain_prefix;
|
||||||
|
_new_path = _base_path || delete_domain_prefix.website_id;
|
||||||
|
EXECUTE FORMAT('COPY (SELECT '''') TO PROGRAM ''mv -T %s %s''', _old_path, _new_path);
|
||||||
|
was_deleted := TRUE;
|
||||||
|
END;
|
||||||
|
$$
|
||||||
|
LANGUAGE plpgsql
|
||||||
|
SECURITY DEFINER;
|
||||||
|
|
||||||
|
GRANT EXECUTE ON FUNCTION api.delete_domain_prefix TO authenticated_user;
|
||||||
|
|
||||||
CREATE TRIGGER update_domain_prefix_last_modified
|
CREATE TRIGGER update_domain_prefix_last_modified
|
||||||
BEFORE INSERT OR UPDATE OR DELETE ON internal.domain_prefix
|
BEFORE INSERT OR UPDATE OR DELETE ON internal.domain_prefix
|
||||||
@@ -51,6 +98,10 @@ DROP TRIGGER track_changes_domain_prefix ON internal.domain_prefix;
|
|||||||
|
|
||||||
DROP TRIGGER update_domain_prefix_last_modified ON internal.domain_prefix;
|
DROP TRIGGER update_domain_prefix_last_modified ON internal.domain_prefix;
|
||||||
|
|
||||||
|
DROP FUNCTION api.set_domain_prefix;
|
||||||
|
|
||||||
|
DROP FUNCTION api.delete_domain_prefix;
|
||||||
|
|
||||||
DROP VIEW api.domain_prefix;
|
DROP VIEW api.domain_prefix;
|
||||||
|
|
||||||
DROP TABLE internal.domain_prefix;
|
DROP TABLE internal.domain_prefix;
|
||||||
|
|||||||
@@ -42,9 +42,7 @@ BEGIN
|
|||||||
w.user_id = $1
|
w.user_id = $1
|
||||||
GROUP BY
|
GROUP BY
|
||||||
w.id,
|
w.id,
|
||||||
w.title
|
w.title', _union_queries);
|
||||||
ORDER BY
|
|
||||||
storage_size_bytes DESC', _union_queries);
|
|
||||||
RETURN QUERY EXECUTE _query
|
RETURN QUERY EXECUTE _query
|
||||||
USING _user_id;
|
USING _user_id;
|
||||||
END;
|
END;
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ DECLARE
|
|||||||
_base_path CONSTANT TEXT := '/var/www/archtika-websites/';
|
_base_path CONSTANT TEXT := '/var/www/archtika-websites/';
|
||||||
_preview_path TEXT;
|
_preview_path TEXT;
|
||||||
_prod_path TEXT;
|
_prod_path TEXT;
|
||||||
|
_article_slug TEXT;
|
||||||
BEGIN
|
BEGIN
|
||||||
IF TG_TABLE_NAME = 'website' THEN
|
IF TG_TABLE_NAME = 'website' THEN
|
||||||
_website_id := OLD.id;
|
_website_id := OLD.id;
|
||||||
@@ -17,7 +18,7 @@ BEGIN
|
|||||||
SELECT
|
SELECT
|
||||||
d.prefix INTO _domain_prefix
|
d.prefix INTO _domain_prefix
|
||||||
FROM
|
FROM
|
||||||
internal.domain_prefix d
|
internal.domain_prefix AS d
|
||||||
WHERE
|
WHERE
|
||||||
d.website_id = _website_id;
|
d.website_id = _website_id;
|
||||||
_preview_path := _base_path || 'previews/' || _website_id;
|
_preview_path := _base_path || 'previews/' || _website_id;
|
||||||
@@ -25,11 +26,20 @@ BEGIN
|
|||||||
IF TG_TABLE_NAME = 'website' THEN
|
IF TG_TABLE_NAME = 'website' THEN
|
||||||
EXECUTE FORMAT('COPY (SELECT '''') TO PROGRAM ''rm -rf %s''', _preview_path);
|
EXECUTE FORMAT('COPY (SELECT '''') TO PROGRAM ''rm -rf %s''', _preview_path);
|
||||||
EXECUTE FORMAT('COPY (SELECT '''') TO PROGRAM ''rm -rf %s''', _prod_path);
|
EXECUTE FORMAT('COPY (SELECT '''') TO PROGRAM ''rm -rf %s''', _prod_path);
|
||||||
ELSE
|
ELSIF TG_TABLE_NAME = 'article' THEN
|
||||||
|
SELECT
|
||||||
|
a.slug INTO _article_slug
|
||||||
|
FROM
|
||||||
|
internal.article AS a
|
||||||
|
WHERE
|
||||||
|
a.id = OLD.id;
|
||||||
|
EXECUTE FORMAT('COPY (SELECT '''') TO PROGRAM ''rm -f %s/articles/%s.html''', _preview_path, _article_slug);
|
||||||
|
EXECUTE FORMAT('COPY (SELECT '''') TO PROGRAM ''rm -f %s/articles/%s.html''', _prod_path, _article_slug);
|
||||||
|
ELSIF TG_TABLE_NAME = 'legal_information' THEN
|
||||||
EXECUTE FORMAT('COPY (SELECT '''') TO PROGRAM ''rm -f %s/legal-information.html''', _preview_path);
|
EXECUTE FORMAT('COPY (SELECT '''') TO PROGRAM ''rm -f %s/legal-information.html''', _preview_path);
|
||||||
EXECUTE FORMAT('COPY (SELECT '''') TO PROGRAM ''rm -f %s/legal-information.html''', _prod_path);
|
EXECUTE FORMAT('COPY (SELECT '''') TO PROGRAM ''rm -f %s/legal-information.html''', _prod_path);
|
||||||
END IF;
|
END IF;
|
||||||
RETURN OLD;
|
RETURN COALESCE(NEW, OLD);
|
||||||
END;
|
END;
|
||||||
$$
|
$$
|
||||||
LANGUAGE plpgsql
|
LANGUAGE plpgsql
|
||||||
@@ -40,6 +50,11 @@ CREATE TRIGGER _cleanup_filesystem_website
|
|||||||
FOR EACH ROW
|
FOR EACH ROW
|
||||||
EXECUTE FUNCTION internal.cleanup_filesystem ();
|
EXECUTE FUNCTION internal.cleanup_filesystem ();
|
||||||
|
|
||||||
|
CREATE TRIGGER _cleanup_filesystem_article
|
||||||
|
BEFORE UPDATE OR DELETE ON internal.article
|
||||||
|
FOR EACH ROW
|
||||||
|
EXECUTE FUNCTION internal.cleanup_filesystem ();
|
||||||
|
|
||||||
CREATE TRIGGER _cleanup_filesystem_legal_information
|
CREATE TRIGGER _cleanup_filesystem_legal_information
|
||||||
BEFORE DELETE ON internal.legal_information
|
BEFORE DELETE ON internal.legal_information
|
||||||
FOR EACH ROW
|
FOR EACH ROW
|
||||||
@@ -48,6 +63,8 @@ CREATE TRIGGER _cleanup_filesystem_legal_information
|
|||||||
-- migrate:down
|
-- migrate:down
|
||||||
DROP TRIGGER _cleanup_filesystem_website ON internal.website;
|
DROP TRIGGER _cleanup_filesystem_website ON internal.website;
|
||||||
|
|
||||||
|
DROP TRIGGER _cleanup_filesystem_article ON internal.article;
|
||||||
|
|
||||||
DROP TRIGGER _cleanup_filesystem_legal_information ON internal.legal_information;
|
DROP TRIGGER _cleanup_filesystem_legal_information ON internal.legal_information;
|
||||||
|
|
||||||
DROP FUNCTION internal.cleanup_filesystem;
|
DROP FUNCTION internal.cleanup_filesystem;
|
||||||
|
|||||||
49
rest-api/db/migrations/20241029160539_export_articles.sql
Normal file
49
rest-api/db/migrations/20241029160539_export_articles.sql
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
-- migrate:up
|
||||||
|
CREATE FUNCTION api.export_articles_zip (website_id UUID)
|
||||||
|
RETURNS "*/*"
|
||||||
|
AS $$
|
||||||
|
DECLARE
|
||||||
|
_has_access BOOLEAN;
|
||||||
|
_headers TEXT;
|
||||||
|
_article RECORD;
|
||||||
|
_markdown_dir TEXT := '/tmp/website-' || export_articles_zip.website_id;
|
||||||
|
BEGIN
|
||||||
|
_has_access = internal.user_has_website_access (export_articles_zip.website_id, 20);
|
||||||
|
|
||||||
|
SELECT
|
||||||
|
FORMAT('[{ "Content-Type": "application/gzip" },'
|
||||||
|
'{ "Content-Disposition": "attachment; filename=\"%s\"" }]',
|
||||||
|
'archtika-export-articles-' || export_articles_zip.website_id || '.tar.gz') INTO _headers;
|
||||||
|
PERFORM
|
||||||
|
SET_CONFIG('response.headers', _headers, TRUE);
|
||||||
|
|
||||||
|
EXECUTE FORMAT('COPY (SELECT '''') TO PROGRAM ''mkdir -p %s''', _markdown_dir || '/articles');
|
||||||
|
|
||||||
|
FOR _article IN (
|
||||||
|
SELECT a.id, a.website_id, a.slug, a.main_content
|
||||||
|
FROM internal.article AS a
|
||||||
|
WHERE a.website_id = export_articles_zip.website_id)
|
||||||
|
LOOP
|
||||||
|
EXECUTE FORMAT(
|
||||||
|
'COPY (SELECT %L) TO ''%s''',
|
||||||
|
_article.main_content,
|
||||||
|
_markdown_dir || '/articles/' || _article.slug || '.md'
|
||||||
|
);
|
||||||
|
END LOOP;
|
||||||
|
|
||||||
|
EXECUTE FORMAT('COPY (SELECT '''') TO PROGRAM ''tar -czf %s -C %s articles && rm %s''',
|
||||||
|
_markdown_dir || '/export.tar.gz',
|
||||||
|
_markdown_dir,
|
||||||
|
_markdown_dir || '/articles/*.md'
|
||||||
|
);
|
||||||
|
|
||||||
|
RETURN pg_read_binary_file(_markdown_dir || '/export.tar.gz');
|
||||||
|
END;
|
||||||
|
$$
|
||||||
|
LANGUAGE plpgsql
|
||||||
|
SECURITY DEFINER;
|
||||||
|
|
||||||
|
GRANT EXECUTE ON FUNCTION api.export_articles_zip TO authenticated_user;
|
||||||
|
|
||||||
|
-- migrate:down
|
||||||
|
DROP FUNCTION api.export_articles_zip;
|
||||||
@@ -11,7 +11,7 @@
|
|||||||
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
|
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
|
||||||
"lint": "prettier --check . && eslint .",
|
"lint": "prettier --check . && eslint .",
|
||||||
"format": "prettier --write .",
|
"format": "prettier --write .",
|
||||||
"gents": "pg-to-ts generate -c postgres://postgres@localhost:15432/archtika -o src/lib/db-schema.ts -s internal"
|
"gents": "pg-to-ts generate -c postgres://postgres@localhost:15432/archtika -o src/lib/db-schema.ts -s internal --datesAsStrings"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@playwright/test": "1.47.0",
|
"@playwright/test": "1.47.0",
|
||||||
|
|||||||
@@ -1,16 +1,30 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
const { date }: { date: Date } = $props();
|
const { date }: { date: string } = $props();
|
||||||
|
|
||||||
const options: Intl.DateTimeFormatOptions = {
|
const dateObject = new Date(date);
|
||||||
year: "numeric",
|
|
||||||
month: "2-digit",
|
const calcTimeAgo = (date: Date) => {
|
||||||
day: "2-digit",
|
const formatter = new Intl.RelativeTimeFormat("en");
|
||||||
hour: "2-digit",
|
const ranges = [
|
||||||
minute: "2-digit",
|
["years", 60 * 60 * 24 * 365],
|
||||||
second: "2-digit"
|
["months", 60 * 60 * 24 * 30],
|
||||||
|
["weeks", 60 * 60 * 24 * 7],
|
||||||
|
["days", 60 * 60 * 24],
|
||||||
|
["hours", 60 * 60],
|
||||||
|
["minutes", 60],
|
||||||
|
["seconds", 1]
|
||||||
|
] as const;
|
||||||
|
const secondsElapsed = (date.getTime() - Date.now()) / 1000;
|
||||||
|
|
||||||
|
for (const [rangeType, rangeVal] of ranges) {
|
||||||
|
if (rangeVal < Math.abs(secondsElapsed)) {
|
||||||
|
const delta = secondsElapsed / rangeVal;
|
||||||
|
return formatter.format(Math.round(delta), rangeType);
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<time datetime={new Date(date).toLocaleString("sv").replace(" ", "T")}>
|
<time datetime={dateObject.toLocaleString("sv").replace(" ", "T")}>
|
||||||
{new Date(date).toLocaleString("en-us", { ...options })}
|
{calcTimeAgo(dateObject)}
|
||||||
</time>
|
</time>
|
||||||
|
|||||||
@@ -9,6 +9,14 @@
|
|||||||
}: { children: Snippet; id: string; text: string; isWider?: boolean } = $props();
|
}: { children: Snippet; id: string; text: string; isWider?: boolean } = $props();
|
||||||
|
|
||||||
const modalId = `${id}-modal`;
|
const modalId = `${id}-modal`;
|
||||||
|
|
||||||
|
$effect(() => {
|
||||||
|
window.addEventListener("keydown", (e) => {
|
||||||
|
if (e.key === "Escape" && window.location.hash === `#${modalId}`) {
|
||||||
|
window.location.hash = "!";
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<a href={`#${modalId}`} role="button">{text}</a>
|
<a href={`#${modalId}`} role="button">{text}</a>
|
||||||
|
|||||||
@@ -17,15 +17,16 @@ export interface Article {
|
|||||||
website_id: string;
|
website_id: string;
|
||||||
user_id: string | null;
|
user_id: string | null;
|
||||||
title: string;
|
title: string;
|
||||||
|
slug: string | null;
|
||||||
meta_description: string | null;
|
meta_description: string | null;
|
||||||
meta_author: string | null;
|
meta_author: string | null;
|
||||||
cover_image: string | null;
|
cover_image: string | null;
|
||||||
publication_date: Date | null;
|
publication_date: string | null;
|
||||||
main_content: string | null;
|
main_content: string | null;
|
||||||
category: string | null;
|
category: string | null;
|
||||||
article_weight: number | null;
|
article_weight: number | null;
|
||||||
created_at: Date;
|
created_at: string;
|
||||||
last_modified_at: Date;
|
last_modified_at: string;
|
||||||
last_modified_by: string | null;
|
last_modified_by: string | null;
|
||||||
}
|
}
|
||||||
export interface ArticleInput {
|
export interface ArticleInput {
|
||||||
@@ -33,15 +34,16 @@ export interface ArticleInput {
|
|||||||
website_id: string;
|
website_id: string;
|
||||||
user_id?: string | null;
|
user_id?: string | null;
|
||||||
title: string;
|
title: string;
|
||||||
|
slug?: string | null;
|
||||||
meta_description?: string | null;
|
meta_description?: string | null;
|
||||||
meta_author?: string | null;
|
meta_author?: string | null;
|
||||||
cover_image?: string | null;
|
cover_image?: string | null;
|
||||||
publication_date?: Date | null;
|
publication_date?: string | null;
|
||||||
main_content?: string | null;
|
main_content?: string | null;
|
||||||
category?: string | null;
|
category?: string | null;
|
||||||
article_weight?: number | null;
|
article_weight?: number | null;
|
||||||
created_at?: Date;
|
created_at?: string;
|
||||||
last_modified_at?: Date;
|
last_modified_at?: string;
|
||||||
last_modified_by?: string | null;
|
last_modified_by?: string | null;
|
||||||
}
|
}
|
||||||
const article = {
|
const article = {
|
||||||
@@ -51,6 +53,7 @@ const article = {
|
|||||||
"website_id",
|
"website_id",
|
||||||
"user_id",
|
"user_id",
|
||||||
"title",
|
"title",
|
||||||
|
"slug",
|
||||||
"meta_description",
|
"meta_description",
|
||||||
"meta_author",
|
"meta_author",
|
||||||
"cover_image",
|
"cover_image",
|
||||||
@@ -81,7 +84,7 @@ export interface ChangeLog {
|
|||||||
website_id: string | null;
|
website_id: string | null;
|
||||||
user_id: string | null;
|
user_id: string | null;
|
||||||
username: string;
|
username: string;
|
||||||
tstamp: Date;
|
tstamp: string;
|
||||||
table_name: string;
|
table_name: string;
|
||||||
operation: string;
|
operation: string;
|
||||||
old_value: any | null;
|
old_value: any | null;
|
||||||
@@ -92,7 +95,7 @@ export interface ChangeLogInput {
|
|||||||
website_id?: string | null;
|
website_id?: string | null;
|
||||||
user_id?: string | null;
|
user_id?: string | null;
|
||||||
username?: string;
|
username?: string;
|
||||||
tstamp?: Date;
|
tstamp?: string;
|
||||||
table_name: string;
|
table_name: string;
|
||||||
operation: string;
|
operation: string;
|
||||||
old_value?: any | null;
|
old_value?: any | null;
|
||||||
@@ -126,16 +129,16 @@ export interface Collab {
|
|||||||
website_id: string;
|
website_id: string;
|
||||||
user_id: string;
|
user_id: string;
|
||||||
permission_level: number;
|
permission_level: number;
|
||||||
added_at: Date;
|
added_at: string;
|
||||||
last_modified_at: Date;
|
last_modified_at: string;
|
||||||
last_modified_by: string | null;
|
last_modified_by: string | null;
|
||||||
}
|
}
|
||||||
export interface CollabInput {
|
export interface CollabInput {
|
||||||
website_id: string;
|
website_id: string;
|
||||||
user_id: string;
|
user_id: string;
|
||||||
permission_level?: number;
|
permission_level?: number;
|
||||||
added_at?: Date;
|
added_at?: string;
|
||||||
last_modified_at?: Date;
|
last_modified_at?: string;
|
||||||
last_modified_by?: string | null;
|
last_modified_by?: string | null;
|
||||||
}
|
}
|
||||||
const collab = {
|
const collab = {
|
||||||
@@ -166,8 +169,8 @@ export interface DocsCategory {
|
|||||||
user_id: string | null;
|
user_id: string | null;
|
||||||
category_name: string;
|
category_name: string;
|
||||||
category_weight: number;
|
category_weight: number;
|
||||||
created_at: Date;
|
created_at: string;
|
||||||
last_modified_at: Date;
|
last_modified_at: string;
|
||||||
last_modified_by: string | null;
|
last_modified_by: string | null;
|
||||||
}
|
}
|
||||||
export interface DocsCategoryInput {
|
export interface DocsCategoryInput {
|
||||||
@@ -176,8 +179,8 @@ export interface DocsCategoryInput {
|
|||||||
user_id?: string | null;
|
user_id?: string | null;
|
||||||
category_name: string;
|
category_name: string;
|
||||||
category_weight: number;
|
category_weight: number;
|
||||||
created_at?: Date;
|
created_at?: string;
|
||||||
last_modified_at?: Date;
|
last_modified_at?: string;
|
||||||
last_modified_by?: string | null;
|
last_modified_by?: string | null;
|
||||||
}
|
}
|
||||||
const docs_category = {
|
const docs_category = {
|
||||||
@@ -207,15 +210,15 @@ const docs_category = {
|
|||||||
export interface DomainPrefix {
|
export interface DomainPrefix {
|
||||||
website_id: string;
|
website_id: string;
|
||||||
prefix: string;
|
prefix: string;
|
||||||
created_at: Date;
|
created_at: string;
|
||||||
last_modified_at: Date;
|
last_modified_at: string;
|
||||||
last_modified_by: string | null;
|
last_modified_by: string | null;
|
||||||
}
|
}
|
||||||
export interface DomainPrefixInput {
|
export interface DomainPrefixInput {
|
||||||
website_id: string;
|
website_id: string;
|
||||||
prefix: string;
|
prefix: string;
|
||||||
created_at?: Date;
|
created_at?: string;
|
||||||
last_modified_at?: Date;
|
last_modified_at?: string;
|
||||||
last_modified_by?: string | null;
|
last_modified_by?: string | null;
|
||||||
}
|
}
|
||||||
const domain_prefix = {
|
const domain_prefix = {
|
||||||
@@ -235,13 +238,13 @@ const domain_prefix = {
|
|||||||
export interface Footer {
|
export interface Footer {
|
||||||
website_id: string;
|
website_id: string;
|
||||||
additional_text: string;
|
additional_text: string;
|
||||||
last_modified_at: Date;
|
last_modified_at: string;
|
||||||
last_modified_by: string | null;
|
last_modified_by: string | null;
|
||||||
}
|
}
|
||||||
export interface FooterInput {
|
export interface FooterInput {
|
||||||
website_id: string;
|
website_id: string;
|
||||||
additional_text: string;
|
additional_text: string;
|
||||||
last_modified_at?: Date;
|
last_modified_at?: string;
|
||||||
last_modified_by?: string | null;
|
last_modified_by?: string | null;
|
||||||
}
|
}
|
||||||
const footer = {
|
const footer = {
|
||||||
@@ -263,7 +266,7 @@ export interface Header {
|
|||||||
logo_type: string;
|
logo_type: string;
|
||||||
logo_text: string | null;
|
logo_text: string | null;
|
||||||
logo_image: string | null;
|
logo_image: string | null;
|
||||||
last_modified_at: Date;
|
last_modified_at: string;
|
||||||
last_modified_by: string | null;
|
last_modified_by: string | null;
|
||||||
}
|
}
|
||||||
export interface HeaderInput {
|
export interface HeaderInput {
|
||||||
@@ -271,7 +274,7 @@ export interface HeaderInput {
|
|||||||
logo_type?: string;
|
logo_type?: string;
|
||||||
logo_text?: string | null;
|
logo_text?: string | null;
|
||||||
logo_image?: string | null;
|
logo_image?: string | null;
|
||||||
last_modified_at?: Date;
|
last_modified_at?: string;
|
||||||
last_modified_by?: string | null;
|
last_modified_by?: string | null;
|
||||||
}
|
}
|
||||||
const header = {
|
const header = {
|
||||||
@@ -300,14 +303,14 @@ export interface Home {
|
|||||||
website_id: string;
|
website_id: string;
|
||||||
main_content: string;
|
main_content: string;
|
||||||
meta_description: string | null;
|
meta_description: string | null;
|
||||||
last_modified_at: Date;
|
last_modified_at: string;
|
||||||
last_modified_by: string | null;
|
last_modified_by: string | null;
|
||||||
}
|
}
|
||||||
export interface HomeInput {
|
export interface HomeInput {
|
||||||
website_id: string;
|
website_id: string;
|
||||||
main_content: string;
|
main_content: string;
|
||||||
meta_description?: string | null;
|
meta_description?: string | null;
|
||||||
last_modified_at?: Date;
|
last_modified_at?: string;
|
||||||
last_modified_by?: string | null;
|
last_modified_by?: string | null;
|
||||||
}
|
}
|
||||||
const home = {
|
const home = {
|
||||||
@@ -333,15 +336,15 @@ const home = {
|
|||||||
export interface LegalInformation {
|
export interface LegalInformation {
|
||||||
website_id: string;
|
website_id: string;
|
||||||
main_content: string;
|
main_content: string;
|
||||||
created_at: Date;
|
created_at: string;
|
||||||
last_modified_at: Date;
|
last_modified_at: string;
|
||||||
last_modified_by: string | null;
|
last_modified_by: string | null;
|
||||||
}
|
}
|
||||||
export interface LegalInformationInput {
|
export interface LegalInformationInput {
|
||||||
website_id: string;
|
website_id: string;
|
||||||
main_content: string;
|
main_content: string;
|
||||||
created_at?: Date;
|
created_at?: string;
|
||||||
last_modified_at?: Date;
|
last_modified_at?: string;
|
||||||
last_modified_by?: string | null;
|
last_modified_by?: string | null;
|
||||||
}
|
}
|
||||||
const legal_information = {
|
const legal_information = {
|
||||||
@@ -365,7 +368,7 @@ export interface Media {
|
|||||||
blob: string;
|
blob: string;
|
||||||
mimetype: string;
|
mimetype: string;
|
||||||
original_name: string;
|
original_name: string;
|
||||||
created_at: Date;
|
created_at: string;
|
||||||
}
|
}
|
||||||
export interface MediaInput {
|
export interface MediaInput {
|
||||||
id?: string;
|
id?: string;
|
||||||
@@ -374,7 +377,7 @@ export interface MediaInput {
|
|||||||
blob: string;
|
blob: string;
|
||||||
mimetype: string;
|
mimetype: string;
|
||||||
original_name: string;
|
original_name: string;
|
||||||
created_at?: Date;
|
created_at?: string;
|
||||||
}
|
}
|
||||||
const media = {
|
const media = {
|
||||||
tableName: "media",
|
tableName: "media",
|
||||||
@@ -397,7 +400,7 @@ export interface Settings {
|
|||||||
background_color_dark_theme: string;
|
background_color_dark_theme: string;
|
||||||
background_color_light_theme: string;
|
background_color_light_theme: string;
|
||||||
favicon_image: string | null;
|
favicon_image: string | null;
|
||||||
last_modified_at: Date;
|
last_modified_at: string;
|
||||||
last_modified_by: string | null;
|
last_modified_by: string | null;
|
||||||
}
|
}
|
||||||
export interface SettingsInput {
|
export interface SettingsInput {
|
||||||
@@ -407,7 +410,7 @@ export interface SettingsInput {
|
|||||||
background_color_dark_theme?: string;
|
background_color_dark_theme?: string;
|
||||||
background_color_light_theme?: string;
|
background_color_light_theme?: string;
|
||||||
favicon_image?: string | null;
|
favicon_image?: string | null;
|
||||||
last_modified_at?: Date;
|
last_modified_at?: string;
|
||||||
last_modified_by?: string | null;
|
last_modified_by?: string | null;
|
||||||
}
|
}
|
||||||
const settings = {
|
const settings = {
|
||||||
@@ -440,7 +443,7 @@ export interface User {
|
|||||||
password_hash: string;
|
password_hash: string;
|
||||||
user_role: string;
|
user_role: string;
|
||||||
max_number_websites: number;
|
max_number_websites: number;
|
||||||
created_at: Date;
|
created_at: string;
|
||||||
}
|
}
|
||||||
export interface UserInput {
|
export interface UserInput {
|
||||||
id?: string;
|
id?: string;
|
||||||
@@ -448,7 +451,7 @@ export interface UserInput {
|
|||||||
password_hash: string;
|
password_hash: string;
|
||||||
user_role?: string;
|
user_role?: string;
|
||||||
max_number_websites?: number;
|
max_number_websites?: number;
|
||||||
created_at?: Date;
|
created_at?: string;
|
||||||
}
|
}
|
||||||
const user = {
|
const user = {
|
||||||
tableName: "user",
|
tableName: "user",
|
||||||
@@ -468,8 +471,8 @@ export interface Website {
|
|||||||
title: string;
|
title: string;
|
||||||
max_storage_size: number;
|
max_storage_size: number;
|
||||||
is_published: boolean;
|
is_published: boolean;
|
||||||
created_at: Date;
|
created_at: string;
|
||||||
last_modified_at: Date;
|
last_modified_at: string;
|
||||||
last_modified_by: string | null;
|
last_modified_by: string | null;
|
||||||
}
|
}
|
||||||
export interface WebsiteInput {
|
export interface WebsiteInput {
|
||||||
@@ -479,8 +482,8 @@ export interface WebsiteInput {
|
|||||||
title: string;
|
title: string;
|
||||||
max_storage_size?: number;
|
max_storage_size?: number;
|
||||||
is_published?: boolean;
|
is_published?: boolean;
|
||||||
created_at?: Date;
|
created_at?: string;
|
||||||
last_modified_at?: Date;
|
last_modified_at?: string;
|
||||||
last_modified_by?: string | null;
|
last_modified_by?: string | null;
|
||||||
}
|
}
|
||||||
const website = {
|
const website = {
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
nestingLevel={1}
|
nestingLevel={1}
|
||||||
{apiUrl}
|
{apiUrl}
|
||||||
title={article.title}
|
title={article.title}
|
||||||
|
slug={article.slug as string}
|
||||||
metaDescription={article.meta_description}
|
metaDescription={article.meta_description}
|
||||||
{websiteUrl}
|
{websiteUrl}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
import Head from "../common/Head.svelte";
|
import Head from "../common/Head.svelte";
|
||||||
import Nav from "../common/Nav.svelte";
|
import Nav from "../common/Nav.svelte";
|
||||||
import Footer from "../common/Footer.svelte";
|
import Footer from "../common/Footer.svelte";
|
||||||
import { md, slugify, type WebsiteOverview } from "$lib/utils";
|
import { md, type WebsiteOverview } from "$lib/utils";
|
||||||
|
|
||||||
const {
|
const {
|
||||||
websiteOverview,
|
websiteOverview,
|
||||||
@@ -62,7 +62,7 @@
|
|||||||
{/if}
|
{/if}
|
||||||
<p>
|
<p>
|
||||||
<strong>
|
<strong>
|
||||||
<a href="./articles/{slugify(article.title)}">{article.title}</a>
|
<a href="./articles/{article.slug}">{article.title}</a>
|
||||||
</strong>
|
</strong>
|
||||||
</p>
|
</p>
|
||||||
{#if article.meta_description}
|
{#if article.meta_description}
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { slugify, type WebsiteOverview } from "../../utils";
|
import { type WebsiteOverview } from "../../utils";
|
||||||
|
|
||||||
const {
|
const {
|
||||||
websiteOverview,
|
websiteOverview,
|
||||||
nestingLevel,
|
nestingLevel,
|
||||||
apiUrl,
|
apiUrl,
|
||||||
title,
|
title,
|
||||||
|
slug,
|
||||||
metaDescription,
|
metaDescription,
|
||||||
websiteUrl
|
websiteUrl
|
||||||
}: {
|
}: {
|
||||||
@@ -13,6 +14,7 @@
|
|||||||
nestingLevel: number;
|
nestingLevel: number;
|
||||||
apiUrl: string;
|
apiUrl: string;
|
||||||
title: string;
|
title: string;
|
||||||
|
slug?: string;
|
||||||
metaDescription?: string | null;
|
metaDescription?: string | null;
|
||||||
websiteUrl: string;
|
websiteUrl: string;
|
||||||
} = $props();
|
} = $props();
|
||||||
@@ -20,7 +22,7 @@
|
|||||||
const constructedTitle =
|
const constructedTitle =
|
||||||
websiteOverview.title === title ? title : `${websiteOverview.title} | ${title}`;
|
websiteOverview.title === title ? title : `${websiteOverview.title} | ${title}`;
|
||||||
|
|
||||||
let ogUrl = `${websiteUrl.replace(/\/$/, "")}${nestingLevel === 0 ? (websiteOverview.title === title ? "" : `/${slugify(title)}`) : `/articles/${slugify(title)}`}`;
|
let ogUrl = `${websiteUrl.replace(/\/$/, "")}${nestingLevel === 0 ? (websiteOverview.title === title ? "" : `/${slug}`) : `/articles/${slug}`}`;
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<svelte:head>
|
<svelte:head>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { type WebsiteOverview, slugify } from "../../utils";
|
import { type WebsiteOverview } from "../../utils";
|
||||||
import type { Article } from "../../db-schema";
|
import type { Article } from "../../db-schema";
|
||||||
|
|
||||||
const {
|
const {
|
||||||
@@ -61,9 +61,9 @@
|
|||||||
<li>
|
<li>
|
||||||
<strong>{key}</strong>
|
<strong>{key}</strong>
|
||||||
<ul>
|
<ul>
|
||||||
{#each categorizedArticles[key] as { title }}
|
{#each categorizedArticles[key] as { title, slug }}
|
||||||
<li>
|
<li>
|
||||||
<a href="{isIndexPage ? './articles' : '.'}/{slugify(title)}">{title}</a>
|
<a href="{isIndexPage ? './articles' : '.'}/{slug}">{title}</a>
|
||||||
</li>
|
</li>
|
||||||
{/each}
|
{/each}
|
||||||
</ul>
|
</ul>
|
||||||
@@ -87,7 +87,7 @@
|
|||||||
/>
|
/>
|
||||||
{/if}
|
{/if}
|
||||||
</svelte:element>
|
</svelte:element>
|
||||||
<label style="margin-inline-start: auto;" for="toggle-theme">
|
<label for="toggle-theme">
|
||||||
<input type="checkbox" id="toggle-theme" hidden />
|
<input type="checkbox" id="toggle-theme" hidden />
|
||||||
<svg
|
<svg
|
||||||
xmlns="http://www.w3.org/2000/svg"
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
|||||||
@@ -19,6 +19,7 @@
|
|||||||
nestingLevel={1}
|
nestingLevel={1}
|
||||||
{apiUrl}
|
{apiUrl}
|
||||||
title={article.title}
|
title={article.title}
|
||||||
|
slug={article.slug as string}
|
||||||
metaDescription={article.meta_description}
|
metaDescription={article.meta_description}
|
||||||
{websiteUrl}
|
{websiteUrl}
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ export const ALLOWED_MIME_TYPES = [
|
|||||||
"image/svg+xml"
|
"image/svg+xml"
|
||||||
];
|
];
|
||||||
|
|
||||||
export const slugify = (string: string) => {
|
const slugify = (string: string) => {
|
||||||
return string
|
return string
|
||||||
.toString()
|
.toString()
|
||||||
.normalize("NFKD") // Normalize Unicode characters
|
.normalize("NFKD") // Normalize Unicode characters
|
||||||
|
|||||||
@@ -76,19 +76,8 @@ export const actions: Actions = {
|
|||||||
const data = await request.formData();
|
const data = await request.formData();
|
||||||
const id = data.get("id");
|
const id = data.get("id");
|
||||||
|
|
||||||
const deleteWebsite = await apiRequest(
|
return await apiRequest(fetch, `${API_BASE_PREFIX}/website?id=eq.${id}`, "DELETE", {
|
||||||
fetch,
|
successMessage: "Successfully deleted website"
|
||||||
`${API_BASE_PREFIX}/website?id=eq.${id}`,
|
});
|
||||||
"DELETE",
|
|
||||||
{
|
|
||||||
successMessage: "Successfully deleted website"
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!deleteWebsite.success) {
|
|
||||||
return deleteWebsite;
|
|
||||||
}
|
|
||||||
|
|
||||||
return deleteWebsite;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -77,7 +77,7 @@
|
|||||||
</details>
|
</details>
|
||||||
|
|
||||||
<ul class="website-grid unpadded">
|
<ul class="website-grid unpadded">
|
||||||
{#each data.websites as { id, user_id, content_type, title, created_at, collab } (id)}
|
{#each data.websites as { id, user_id, content_type, title, created_at, last_modified_at, collab } (id)}
|
||||||
<li class="website-card">
|
<li class="website-card">
|
||||||
<p>
|
<p>
|
||||||
<strong>
|
<strong>
|
||||||
@@ -90,9 +90,13 @@
|
|||||||
{content_type}
|
{content_type}
|
||||||
</li>
|
</li>
|
||||||
<li>
|
<li>
|
||||||
<strong>Created at:</strong>
|
<strong>Created:</strong>
|
||||||
<DateTime date={created_at} />
|
<DateTime date={created_at} />
|
||||||
</li>
|
</li>
|
||||||
|
<li>
|
||||||
|
<strong>Last modified:</strong>
|
||||||
|
<DateTime date={last_modified_at} />
|
||||||
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
<div class="website-card__actions">
|
<div class="website-card__actions">
|
||||||
<Modal id="update-website-{id}" text="Update">
|
<Modal id="update-website-{id}" text="Update">
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { API_BASE_PREFIX, apiRequest } from "$lib/server/utils";
|
|||||||
export const load: PageServerLoad = async ({ fetch, locals }) => {
|
export const load: PageServerLoad = async ({ fetch, locals }) => {
|
||||||
const storageSizes = await apiRequest(
|
const storageSizes = await apiRequest(
|
||||||
fetch,
|
fetch,
|
||||||
`${API_BASE_PREFIX}/rpc/user_websites_storage_size`,
|
`${API_BASE_PREFIX}/rpc/user_websites_storage_size?order=max_storage_bytes.desc`,
|
||||||
"GET",
|
"GET",
|
||||||
{
|
{
|
||||||
returnData: true
|
returnData: true
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ export const load: PageServerLoad = async ({ fetch, url }) => {
|
|||||||
const usersWithWebsites: (User & { website: Website[] })[] = (
|
const usersWithWebsites: (User & { website: Website[] })[] = (
|
||||||
await apiRequest(
|
await apiRequest(
|
||||||
fetch,
|
fetch,
|
||||||
`${API_BASE_PREFIX}/user?select=*,website!user_id(*)&order=created_at&limit=${PAGINATION_MAX_ITEMS}&offset=${resultOffset}`,
|
`${API_BASE_PREFIX}/user?select=*,website!user_id(*)&order=created_at&website.order=created_at.desc&limit=${PAGINATION_MAX_ITEMS}&offset=${resultOffset}`,
|
||||||
"GET",
|
"GET",
|
||||||
{
|
{
|
||||||
returnData: true
|
returnData: true
|
||||||
@@ -61,7 +61,7 @@ export const actions: Actions = {
|
|||||||
body: {
|
body: {
|
||||||
max_storage_size: data.get("storage-size")
|
max_storage_size: data.get("storage-size")
|
||||||
},
|
},
|
||||||
successMessage: "Successfully updated user website storage size"
|
successMessage: "Successfully updated website storage"
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import type { Actions, PageServerLoad } from "./$types";
|
import type { Actions, PageServerLoad } from "./$types";
|
||||||
import { API_BASE_PREFIX } from "$lib/server/utils";
|
import { API_BASE_PREFIX } from "$lib/server/utils";
|
||||||
import { apiRequest } from "$lib/server/utils";
|
import { apiRequest } from "$lib/server/utils";
|
||||||
|
import { parse } from "node:path";
|
||||||
import type { Article, DocsCategory } from "$lib/db-schema";
|
import type { Article, DocsCategory } from "$lib/db-schema";
|
||||||
|
|
||||||
export const load: PageServerLoad = async ({ params, fetch, url, parent, locals }) => {
|
export const load: PageServerLoad = async ({ params, fetch, url, parent, locals }) => {
|
||||||
@@ -58,6 +59,7 @@ export const load: PageServerLoad = async ({ params, fetch, url, parent, locals
|
|||||||
website,
|
website,
|
||||||
home,
|
home,
|
||||||
permissionLevel,
|
permissionLevel,
|
||||||
|
API_BASE_PREFIX,
|
||||||
user: locals.user
|
user: locals.user
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@@ -74,6 +76,25 @@ export const actions: Actions = {
|
|||||||
successMessage: "Successfully created article"
|
successMessage: "Successfully created article"
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
importArticles: async ({ request, fetch, params }) => {
|
||||||
|
const data = await request.formData();
|
||||||
|
const files = data.getAll("import-articles") as File[];
|
||||||
|
|
||||||
|
const articles = await Promise.all(
|
||||||
|
files.map(async (file) => {
|
||||||
|
return {
|
||||||
|
website_id: params.websiteId,
|
||||||
|
title: parse(file.name).name,
|
||||||
|
main_content: await file.text()
|
||||||
|
};
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
return await apiRequest(fetch, `${API_BASE_PREFIX}/article`, "POST", {
|
||||||
|
body: articles,
|
||||||
|
successMessage: "Successfully imported articles"
|
||||||
|
});
|
||||||
|
},
|
||||||
deleteArticle: async ({ request, fetch }) => {
|
deleteArticle: async ({ request, fetch }) => {
|
||||||
const data = await request.formData();
|
const data = await request.formData();
|
||||||
|
|
||||||
|
|||||||
@@ -31,18 +31,37 @@
|
|||||||
<a href="#create-article">Create article</a>
|
<a href="#create-article">Create article</a>
|
||||||
</h2>
|
</h2>
|
||||||
|
|
||||||
<Modal id="create-article" text="Create article">
|
<div class="multi-wrapper">
|
||||||
<h3>Create article</h3>
|
<Modal id="create-article" text="Create article">
|
||||||
|
<h3>Create article</h3>
|
||||||
<form method="POST" action="?/createArticle" use:enhance={enhanceForm({ closeModal: true })}>
|
<form
|
||||||
<label>
|
method="POST"
|
||||||
Title:
|
action="?/createArticle"
|
||||||
<input type="text" name="title" pattern="\S(.*\S)?" maxlength="100" required />
|
use:enhance={enhanceForm({ closeModal: true })}
|
||||||
</label>
|
>
|
||||||
|
<label>
|
||||||
<button type="submit" disabled={data.permissionLevel === 10}>Create article</button>
|
Title:
|
||||||
</form>
|
<input type="text" name="title" pattern="\S(.*\S)?" maxlength="100" required />
|
||||||
</Modal>
|
</label>
|
||||||
|
<button type="submit" disabled={data.permissionLevel === 10}>Create article</button>
|
||||||
|
</form>
|
||||||
|
</Modal>
|
||||||
|
<Modal id="import-articles" text="Import articles">
|
||||||
|
<h3>Import articles</h3>
|
||||||
|
<form
|
||||||
|
method="POST"
|
||||||
|
action="?/importArticles"
|
||||||
|
enctype="multipart/form-data"
|
||||||
|
use:enhance={enhanceForm({ closeModal: true })}
|
||||||
|
>
|
||||||
|
<label>
|
||||||
|
Markdown files:
|
||||||
|
<input type="file" name="import-articles" accept=".md" multiple required />
|
||||||
|
</label>
|
||||||
|
<button type="submit" disabled={data.permissionLevel === 10}>Import articles</button>
|
||||||
|
</form>
|
||||||
|
</Modal>
|
||||||
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
{#if data.totalArticleCount > 0}
|
{#if data.totalArticleCount > 0}
|
||||||
@@ -51,6 +70,11 @@
|
|||||||
<a href="#all-articles">All articles</a>
|
<a href="#all-articles">All articles</a>
|
||||||
</h2>
|
</h2>
|
||||||
|
|
||||||
|
<a
|
||||||
|
class="export-anchor"
|
||||||
|
href={`${data.API_BASE_PREFIX}/rpc/export_articles_zip?website_id=${data.website.id}`}
|
||||||
|
>Export articles</a
|
||||||
|
>
|
||||||
<details>
|
<details>
|
||||||
<summary>Search & Filter</summary>
|
<summary>Search & Filter</summary>
|
||||||
<form method="GET">
|
<form method="GET">
|
||||||
@@ -92,7 +116,6 @@
|
|||||||
fill="currentColor"
|
fill="currentColor"
|
||||||
width="16"
|
width="16"
|
||||||
height="16"
|
height="16"
|
||||||
style="vertical-align: middle"
|
|
||||||
>
|
>
|
||||||
<path
|
<path
|
||||||
fill-rule="evenodd"
|
fill-rule="evenodd"
|
||||||
@@ -160,4 +183,15 @@
|
|||||||
gap: var(--space-s);
|
gap: var(--space-s);
|
||||||
align-items: center;
|
align-items: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.multi-wrapper {
|
||||||
|
display: flex;
|
||||||
|
gap: var(--space-s);
|
||||||
|
flex-wrap: wrap;
|
||||||
|
align-items: start;
|
||||||
|
}
|
||||||
|
|
||||||
|
.export-anchor {
|
||||||
|
max-inline-size: fit-content;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -36,7 +36,13 @@
|
|||||||
<form method="POST" action="?/createCategory" use:enhance={enhanceForm({ closeModal: true })}>
|
<form method="POST" action="?/createCategory" use:enhance={enhanceForm({ closeModal: true })}>
|
||||||
<label>
|
<label>
|
||||||
Name:
|
Name:
|
||||||
<input type="text" name="category-name" maxlength="50" required />
|
<input
|
||||||
|
type="text"
|
||||||
|
name="category-name"
|
||||||
|
maxlength="50"
|
||||||
|
pattern="^(?!Uncategorized$).+$"
|
||||||
|
required
|
||||||
|
/>
|
||||||
</label>
|
</label>
|
||||||
|
|
||||||
<label>
|
<label>
|
||||||
@@ -80,6 +86,7 @@
|
|||||||
name="category-name"
|
name="category-name"
|
||||||
value={category_name}
|
value={category_name}
|
||||||
maxlength="50"
|
maxlength="50"
|
||||||
|
pattern="^(?!Uncategorized$).+$"
|
||||||
required
|
required
|
||||||
/>
|
/>
|
||||||
</label>
|
</label>
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ export const actions: Actions = {
|
|||||||
});
|
});
|
||||||
},
|
},
|
||||||
deleteLegalInformation: async ({ fetch, params }) => {
|
deleteLegalInformation: async ({ fetch, params }) => {
|
||||||
const deleteLegalInformation = await apiRequest(
|
return await apiRequest(
|
||||||
fetch,
|
fetch,
|
||||||
`${API_BASE_PREFIX}/legal_information?website_id=eq.${params.websiteId}`,
|
`${API_BASE_PREFIX}/legal_information?website_id=eq.${params.websiteId}`,
|
||||||
"DELETE",
|
"DELETE",
|
||||||
@@ -52,12 +52,6 @@ export const actions: Actions = {
|
|||||||
successMessage: "Successfully deleted legal information"
|
successMessage: "Successfully deleted legal information"
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!deleteLegalInformation.success) {
|
|
||||||
return deleteLegalInformation;
|
|
||||||
}
|
|
||||||
|
|
||||||
return deleteLegalInformation;
|
|
||||||
},
|
},
|
||||||
pasteImage: async ({ request, fetch, params }) => {
|
pasteImage: async ({ request, fetch, params }) => {
|
||||||
const data = await request.formData();
|
const data = await request.formData();
|
||||||
|
|||||||
@@ -106,7 +106,7 @@
|
|||||||
<th>User</th>
|
<th>User</th>
|
||||||
<th>Resource</th>
|
<th>Resource</th>
|
||||||
<th>Operation</th>
|
<th>Operation</th>
|
||||||
<th>Date & Time</th>
|
<th>Time</th>
|
||||||
<th>Changes</th>
|
<th>Changes</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
@@ -140,21 +140,20 @@
|
|||||||
<button type="submit">Compute diff</button>
|
<button type="submit">Compute diff</button>
|
||||||
</form>
|
</form>
|
||||||
{#if form?.logId === id && form?.currentDiff}
|
{#if form?.logId === id && form?.currentDiff}
|
||||||
<pre style="white-space: pre-wrap">{@html DOMPurify.sanitize(
|
<pre>{@html DOMPurify.sanitize(form.currentDiff, {
|
||||||
form.currentDiff,
|
ALLOWED_TAGS: ["ins", "del"]
|
||||||
{ ALLOWED_TAGS: ["ins", "del"] }
|
})}</pre>
|
||||||
)}</pre>
|
|
||||||
{/if}
|
{/if}
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
{#if new_value && !old_value}
|
{#if new_value && !old_value}
|
||||||
<h4>New value</h4>
|
<h4>New value</h4>
|
||||||
<pre style="white-space: pre-wrap">{DOMPurify.sanitize(newValue)}</pre>
|
<pre>{DOMPurify.sanitize(newValue)}</pre>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
{#if old_value && !new_value}
|
{#if old_value && !new_value}
|
||||||
<h4>Old value</h4>
|
<h4>Old value</h4>
|
||||||
<pre style="white-space: pre-wrap">{DOMPurify.sanitize(oldValue)}</pre>
|
<pre>{DOMPurify.sanitize(oldValue)}</pre>
|
||||||
{/if}
|
{/if}
|
||||||
</Modal>
|
</Modal>
|
||||||
</td>
|
</td>
|
||||||
@@ -169,3 +168,9 @@
|
|||||||
/>
|
/>
|
||||||
</section>
|
</section>
|
||||||
</WebsiteEditor>
|
</WebsiteEditor>
|
||||||
|
|
||||||
|
<style>
|
||||||
|
pre {
|
||||||
|
white-space: pre-wrap;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|||||||
@@ -4,25 +4,24 @@ import BlogArticle from "$lib/templates/blog/BlogArticle.svelte";
|
|||||||
import BlogIndex from "$lib/templates/blog/BlogIndex.svelte";
|
import BlogIndex from "$lib/templates/blog/BlogIndex.svelte";
|
||||||
import DocsArticle from "$lib/templates/docs/DocsArticle.svelte";
|
import DocsArticle from "$lib/templates/docs/DocsArticle.svelte";
|
||||||
import DocsIndex from "$lib/templates/docs/DocsIndex.svelte";
|
import DocsIndex from "$lib/templates/docs/DocsIndex.svelte";
|
||||||
import { type WebsiteOverview, hexToHSL, slugify } from "$lib/utils";
|
import { type WebsiteOverview, hexToHSL } from "$lib/utils";
|
||||||
import { mkdir, readFile, rename, writeFile, chmod, readdir } from "node:fs/promises";
|
import { mkdir, readFile, writeFile, chmod, readdir } from "node:fs/promises";
|
||||||
import { join } from "node:path";
|
import { join } from "node:path";
|
||||||
import { render } from "svelte/server";
|
import { render } from "svelte/server";
|
||||||
import type { Actions, PageServerLoad } from "./$types";
|
import type { Actions, PageServerLoad } from "./$types";
|
||||||
|
|
||||||
|
const getOverviewFetchUrl = (websiteId: string) => {
|
||||||
|
return `${API_BASE_PREFIX}/website?id=eq.${websiteId}&select=*,settings(*),header(*),home(*),footer(*),article(*,docs_category(*)),legal_information(*),domain_prefix(*)`;
|
||||||
|
};
|
||||||
|
|
||||||
export const load: PageServerLoad = async ({ params, fetch, parent }) => {
|
export const load: PageServerLoad = async ({ params, fetch, parent }) => {
|
||||||
const websiteOverview: WebsiteOverview = (
|
const websiteOverview: WebsiteOverview = (
|
||||||
await apiRequest(
|
await apiRequest(fetch, getOverviewFetchUrl(params.websiteId), "GET", {
|
||||||
fetch,
|
headers: {
|
||||||
`${API_BASE_PREFIX}/website?id=eq.${params.websiteId}&select=*,settings(*),header(*),home(*),footer(*),article(*,docs_category(*)),legal_information(*),domain_prefix(*)`,
|
Accept: "application/vnd.pgrst.object+json"
|
||||||
"GET",
|
},
|
||||||
{
|
returnData: true
|
||||||
headers: {
|
})
|
||||||
Accept: "application/vnd.pgrst.object+json"
|
|
||||||
},
|
|
||||||
returnData: true
|
|
||||||
}
|
|
||||||
)
|
|
||||||
).data;
|
).data;
|
||||||
|
|
||||||
const { websitePreviewUrl, websiteProdUrl } = await generateStaticFiles(websiteOverview);
|
const { websitePreviewUrl, websiteProdUrl } = await generateStaticFiles(websiteOverview);
|
||||||
@@ -40,22 +39,15 @@ export const load: PageServerLoad = async ({ params, fetch, parent }) => {
|
|||||||
export const actions: Actions = {
|
export const actions: Actions = {
|
||||||
publishWebsite: async ({ fetch, params }) => {
|
publishWebsite: async ({ fetch, params }) => {
|
||||||
const websiteOverview: WebsiteOverview = (
|
const websiteOverview: WebsiteOverview = (
|
||||||
await apiRequest(
|
await apiRequest(fetch, getOverviewFetchUrl(params.websiteId), "GET", {
|
||||||
fetch,
|
headers: {
|
||||||
`${API_BASE_PREFIX}/website?id=eq.${params.websiteId}&select=*,settings(*),header(*),home(*),footer(*),article(*,docs_category(*)),legal_information(*),domain_prefix(*)`,
|
Accept: "application/vnd.pgrst.object+json"
|
||||||
"GET",
|
},
|
||||||
{
|
returnData: true
|
||||||
headers: {
|
})
|
||||||
Accept: "application/vnd.pgrst.object+json"
|
|
||||||
},
|
|
||||||
returnData: true
|
|
||||||
}
|
|
||||||
)
|
|
||||||
).data;
|
).data;
|
||||||
|
|
||||||
await generateStaticFiles(websiteOverview, false);
|
const publish = await apiRequest(
|
||||||
|
|
||||||
return await apiRequest(
|
|
||||||
fetch,
|
fetch,
|
||||||
`${API_BASE_PREFIX}/website?id=eq.${params.websiteId}`,
|
`${API_BASE_PREFIX}/website?id=eq.${params.websiteId}`,
|
||||||
"PATCH",
|
"PATCH",
|
||||||
@@ -66,78 +58,33 @@ export const actions: Actions = {
|
|||||||
successMessage: "Successfully published website"
|
successMessage: "Successfully published website"
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (!publish.success) {
|
||||||
|
return publish;
|
||||||
|
}
|
||||||
|
|
||||||
|
await generateStaticFiles(websiteOverview, false);
|
||||||
|
|
||||||
|
return publish;
|
||||||
},
|
},
|
||||||
createUpdateCustomDomainPrefix: async ({ request, fetch, params }) => {
|
createUpdateCustomDomainPrefix: async ({ request, fetch, params }) => {
|
||||||
const data = await request.formData();
|
const data = await request.formData();
|
||||||
|
|
||||||
const oldDomainPrefix = (
|
return await apiRequest(fetch, `${API_BASE_PREFIX}/rpc/set_domain_prefix`, "POST", {
|
||||||
await apiRequest(
|
|
||||||
fetch,
|
|
||||||
`${API_BASE_PREFIX}/domain_prefix?website_id=eq.${params.websiteId}`,
|
|
||||||
"GET",
|
|
||||||
{
|
|
||||||
headers: {
|
|
||||||
Accept: "application/vnd.pgrst.object+json"
|
|
||||||
},
|
|
||||||
returnData: true
|
|
||||||
}
|
|
||||||
)
|
|
||||||
).data;
|
|
||||||
|
|
||||||
const newDomainPrefix = await apiRequest(fetch, `${API_BASE_PREFIX}/domain_prefix`, "POST", {
|
|
||||||
headers: {
|
|
||||||
Prefer: "resolution=merge-duplicates",
|
|
||||||
Accept: "application/vnd.pgrst.object+json"
|
|
||||||
},
|
|
||||||
body: {
|
body: {
|
||||||
website_id: params.websiteId,
|
website_id: params.websiteId,
|
||||||
prefix: data.get("domain-prefix")
|
prefix: data.get("domain-prefix")
|
||||||
},
|
},
|
||||||
successMessage: "Successfully created/updated domain prefix"
|
successMessage: "Successfully created/updated domain prefix"
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!newDomainPrefix.success) {
|
|
||||||
return newDomainPrefix;
|
|
||||||
}
|
|
||||||
|
|
||||||
await rename(
|
|
||||||
join(
|
|
||||||
"/",
|
|
||||||
"var",
|
|
||||||
"www",
|
|
||||||
"archtika-websites",
|
|
||||||
oldDomainPrefix?.prefix ? oldDomainPrefix.prefix : params.websiteId
|
|
||||||
),
|
|
||||||
join("/", "var", "www", "archtika-websites", data.get("domain-prefix") as string)
|
|
||||||
);
|
|
||||||
|
|
||||||
return newDomainPrefix;
|
|
||||||
},
|
},
|
||||||
deleteCustomDomainPrefix: async ({ fetch, params }) => {
|
deleteCustomDomainPrefix: async ({ fetch, params }) => {
|
||||||
const customPrefix = await apiRequest(
|
return await apiRequest(fetch, `${API_BASE_PREFIX}/rpc/delete_domain_prefix`, "POST", {
|
||||||
fetch,
|
body: {
|
||||||
`${API_BASE_PREFIX}/domain_prefix?website_id=eq.${params.websiteId}`,
|
website_id: params.websiteId
|
||||||
"DELETE",
|
},
|
||||||
{
|
successMessage: "Successfully deleted domain prefix"
|
||||||
headers: {
|
});
|
||||||
Prefer: "return=representation",
|
|
||||||
Accept: "application/vnd.pgrst.object+json"
|
|
||||||
},
|
|
||||||
successMessage: "Successfully deleted domain prefix",
|
|
||||||
returnData: true
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!customPrefix.success) {
|
|
||||||
return customPrefix;
|
|
||||||
}
|
|
||||||
|
|
||||||
await rename(
|
|
||||||
join("/", "var", "www", "archtika-websites", customPrefix.data.prefix),
|
|
||||||
join("/", "var", "www", "archtika-websites", params.websiteId)
|
|
||||||
);
|
|
||||||
|
|
||||||
return customPrefix;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -211,10 +158,7 @@ const generateStaticFiles = async (websiteData: WebsiteOverview, isPreview = tru
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
await writeFile(
|
await writeFile(join(uploadDir, "articles", `${article.slug}.html`), fileContents(head, body));
|
||||||
join(uploadDir, "articles", `${slugify(article.title)}.html`),
|
|
||||||
fileContents(head, body)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (websiteData.legal_information) {
|
if (websiteData.legal_information) {
|
||||||
|
|||||||
@@ -71,7 +71,7 @@
|
|||||||
placeholder="my-blog"
|
placeholder="my-blog"
|
||||||
minlength="3"
|
minlength="3"
|
||||||
maxlength="16"
|
maxlength="16"
|
||||||
pattern="^[a-z]+(-[a-z]+)*$"
|
pattern="^(?!previews$)[a-z]+(-[a-z]+)*$"
|
||||||
required
|
required
|
||||||
/>
|
/>
|
||||||
</label>
|
</label>
|
||||||
|
|||||||
@@ -88,11 +88,16 @@ summary {
|
|||||||
background-color: var(--bg-secondary);
|
background-color: var(--bg-secondary);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
summary:has(svg),
|
||||||
label:has(svg) {
|
label:has(svg) {
|
||||||
display: inline-grid;
|
display: inline-grid;
|
||||||
place-content: center;
|
place-content: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
label[for="toggle-theme"] {
|
||||||
|
margin-inline-start: auto;
|
||||||
|
}
|
||||||
|
|
||||||
label[for="toggle-theme"] svg:first-of-type {
|
label[for="toggle-theme"] svg:first-of-type {
|
||||||
display: var(--display-light);
|
display: var(--display-light);
|
||||||
}
|
}
|
||||||
@@ -113,6 +118,7 @@ label[for="toggle-theme"] svg:last-of-type {
|
|||||||
}
|
}
|
||||||
|
|
||||||
button:disabled {
|
button:disabled {
|
||||||
|
user-select: none;
|
||||||
pointer-events: none;
|
pointer-events: none;
|
||||||
opacity: 0.5;
|
opacity: 0.5;
|
||||||
z-index: -10;
|
z-index: -10;
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { test, expect } from "@playwright/test";
|
import { test, expect } from "@playwright/test";
|
||||||
|
import { randomBytes } from "node:crypto";
|
||||||
import {
|
import {
|
||||||
userOwner,
|
userOwner,
|
||||||
authenticate,
|
authenticate,
|
||||||
@@ -7,6 +8,8 @@ import {
|
|||||||
collabTestingWebsite
|
collabTestingWebsite
|
||||||
} from "./shared";
|
} from "./shared";
|
||||||
|
|
||||||
|
const genArticleName = () => randomBytes(12).toString("hex");
|
||||||
|
|
||||||
test.describe("Website owner", () => {
|
test.describe("Website owner", () => {
|
||||||
test.beforeEach(async ({ page }) => {
|
test.beforeEach(async ({ page }) => {
|
||||||
await authenticate(userOwner, page);
|
await authenticate(userOwner, page);
|
||||||
@@ -21,7 +24,7 @@ test.describe("Website owner", () => {
|
|||||||
test(`Create article`, async ({ page }) => {
|
test(`Create article`, async ({ page }) => {
|
||||||
await page.getByRole("button", { name: "Create article" }).click();
|
await page.getByRole("button", { name: "Create article" }).click();
|
||||||
await page.locator("#create-article-modal").getByLabel("Title:").click();
|
await page.locator("#create-article-modal").getByLabel("Title:").click();
|
||||||
await page.locator("#create-article-modal").getByLabel("Title:").fill("Article");
|
await page.locator("#create-article-modal").getByLabel("Title:").fill(genArticleName());
|
||||||
await page
|
await page
|
||||||
.locator("#create-article-modal")
|
.locator("#create-article-modal")
|
||||||
.getByRole("button", { name: "Create article" })
|
.getByRole("button", { name: "Create article" })
|
||||||
@@ -34,7 +37,7 @@ test.describe("Website owner", () => {
|
|||||||
test.beforeEach(async ({ page }) => {
|
test.beforeEach(async ({ page }) => {
|
||||||
await page.getByRole("button", { name: "Create article" }).click();
|
await page.getByRole("button", { name: "Create article" }).click();
|
||||||
await page.locator("#create-article-modal").getByLabel("Title:").click();
|
await page.locator("#create-article-modal").getByLabel("Title:").click();
|
||||||
await page.locator("#create-article-modal").getByLabel("Title:").fill("Article");
|
await page.locator("#create-article-modal").getByLabel("Title:").fill(genArticleName());
|
||||||
await page
|
await page
|
||||||
.locator("#create-article-modal")
|
.locator("#create-article-modal")
|
||||||
.getByRole("button", { name: "Create article" })
|
.getByRole("button", { name: "Create article" })
|
||||||
@@ -81,7 +84,7 @@ for (const permissionLevel of permissionLevels) {
|
|||||||
test(`Create article`, async ({ page }) => {
|
test(`Create article`, async ({ page }) => {
|
||||||
await page.getByRole("button", { name: "Create article" }).click();
|
await page.getByRole("button", { name: "Create article" }).click();
|
||||||
await page.locator("#create-article-modal").getByLabel("Title:").click();
|
await page.locator("#create-article-modal").getByLabel("Title:").click();
|
||||||
await page.locator("#create-article-modal").getByLabel("Title:").fill("Article");
|
await page.locator("#create-article-modal").getByLabel("Title:").fill(genArticleName());
|
||||||
await page
|
await page
|
||||||
.locator("#create-article-modal")
|
.locator("#create-article-modal")
|
||||||
.getByRole("button", { name: "Create article" })
|
.getByRole("button", { name: "Create article" })
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ test(`Update user website storage limit`, async ({ page }) => {
|
|||||||
.locator("details")
|
.locator("details")
|
||||||
.getByRole("button", { name: "Update storage limit" })
|
.getByRole("button", { name: "Update storage limit" })
|
||||||
.click();
|
.click();
|
||||||
await expect(page.getByText("Successfully updated user website storage size")).toBeVisible();
|
await expect(page.getByText("Successfully updated website storage")).toBeVisible();
|
||||||
});
|
});
|
||||||
|
|
||||||
test(`Delete user`, async ({ page }) => {
|
test(`Delete user`, async ({ page }) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user