fix: incorrect test

This commit is contained in:
Jacky Zhao 2023-12-02 16:52:44 -08:00
parent 82bd08d14a
commit 610b04406f
2 changed files with 3 additions and 3 deletions

View File

@ -83,7 +83,7 @@ describe("transforms", () => {
test("simplifySlug", () => { test("simplifySlug", () => {
asserts( asserts(
[ [
["index", ""], ["index", "/"],
["abc", "abc"], ["abc", "abc"],
["abc/index", "abc/"], ["abc/index", "abc/"],
["abc/def", "abc/def"], ["abc/def", "abc/def"],

View File

@ -1,5 +1,5 @@
import { slug } from "github-slugger" import { slug } from "github-slugger"
import type { ElementContent, Element as HastElement } from "hast" import type { Element as HastElement } from "hast"
// this file must be isomorphic so it can't use node libs (e.g. path) // this file must be isomorphic so it can't use node libs (e.g. path)
export const QUARTZ = "quartz" export const QUARTZ = "quartz"
@ -25,7 +25,7 @@ export function isFullSlug(s: string): s is FullSlug {
/** Shouldn't be a relative path and shouldn't have `/index` as an ending or a file extension. It _can_ however have a trailing slash to indicate a folder path. */ /** Shouldn't be a relative path and shouldn't have `/index` as an ending or a file extension. It _can_ however have a trailing slash to indicate a folder path. */
export type SimpleSlug = SlugLike<"simple"> export type SimpleSlug = SlugLike<"simple">
export function isSimpleSlug(s: string): s is SimpleSlug { export function isSimpleSlug(s: string): s is SimpleSlug {
const validStart = !(s.startsWith(".") || s.startsWith("/")) const validStart = !(s.startsWith(".") || (s.length > 1 && s.startsWith("/")))
const validEnding = !(s.endsWith("/index") || s === "index") const validEnding = !(s.endsWith("/index") || s === "index")
return validStart && !_containsForbiddenCharacters(s) && validEnding && !_hasFileExtension(s) return validStart && !_containsForbiddenCharacters(s) && validEnding && !_hasFileExtension(s)
} }