New IDs
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { getCategoriesCached, getCategoriesCachedByRef, getCategoryCached } from './category';
|
||||
import { getUser, getUsersCached, getUsersCachedByRef } from './user';
|
||||
import { getCategoriesCachedByRef, getCategoryCached } from './category';
|
||||
import { getUser, getUsersCachedByRef } from './user';
|
||||
|
||||
/**
|
||||
* @typedef {import('$types/base').Post} Post
|
||||
@@ -40,7 +40,7 @@ export async function getPosts(sql, category = undefined, limit = 10, offset = 0
|
||||
filter = sql``;
|
||||
} else {
|
||||
filter = sql`WHERE category_id = ${ category.id }`;
|
||||
}
|
||||
}
|
||||
|
||||
const query = sql`
|
||||
SELECT id, author_id, name, category_id, latest_content, created_date, likes, dislikes
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
import { goto } from "$app/navigation";
|
||||
|
||||
/**
|
||||
* @param {string | undefined} name
|
||||
* @returns {number | null}
|
||||
*/
|
||||
export function getIdFromName(name) {
|
||||
const parts = (name || "").split("-", 2);
|
||||
const parsed = parseInt(parts[0]);
|
||||
|
||||
return Number.isNaN(parsed) ? null : parsed;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {number} id
|
||||
* @param {string} name
|
||||
* @returns {string}
|
||||
*/
|
||||
export function getNamedId(id, name) {
|
||||
const convertedName = name.replace(/[^\w\d]/g, '-').toLowerCase();
|
||||
return `${id}-${convertedName}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {number} id
|
||||
* @param {string} name
|
||||
*/
|
||||
export function gotoNamedId(id, name) {
|
||||
const page = getNamedId(id, name);
|
||||
goto(page, { replaceState: true });
|
||||
}
|
||||
Reference in New Issue
Block a user