/*1* This file is part of CoCalc: Copyright © 2023 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45import { NewsItem } from "./types/news";67// Slug URL, based on the title and with "-[id]" at the end.8// https://www.semrush.com/blog/what-is-a-url-slug/9// The main point here is to have a URL that contains unique information and is human readable.10export function slugURL(news?: Pick<NewsItem, "id" | "title">): string {11if (!news || !news.title || !news.id) return "/news";12const { title, id } = news;13const shortTitle = title14.toLowerCase()15// limit the max length, too long URLs are bad as well16.slice(0, 200)17// replace all non-alphanumeric characters with a space18.replace(/[^a-zA-Z0-9]/g, " ")19// replace multiple spaces with a single dash20.replace(/\s+/g, "-");21return `/news/${shortTitle}-${id}`;22}232425