mirror of
https://github.com/MadsLorentzen/ai-job-search.git
synced 2026-09-17 08:36:25 +00:00
fix(portal-clis): accept full posting URLs in jobbank, jobdanmark, and jobnet detail commands (#430)
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { defineCommand, option } from "@bunli/core"
|
||||
import { z } from "zod"
|
||||
import { parse } from "node-html-parser"
|
||||
import { BASE_URL, writeError } from "../helpers.js"
|
||||
import { BASE_URL, normalizeSlug, writeError } from "../helpers.js"
|
||||
import { extractCity, toContractDate } from "./search.js"
|
||||
|
||||
interface JsonLdJobPosting {
|
||||
@@ -226,12 +226,18 @@ export const detail = defineCommand({
|
||||
handler: async ({ flags, positional, signal }) => {
|
||||
if (signal.aborted) return
|
||||
|
||||
const slug = positional[0]
|
||||
if (!slug) {
|
||||
const rawSlug = positional[0]
|
||||
if (!rawSlug) {
|
||||
writeError("slug argument is required", "MISSING_REQUIRED")
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
const slug = normalizeSlug(rawSlug)
|
||||
if (!slug) {
|
||||
writeError(`Could not extract slug from "${rawSlug}"`, "BAD_ID")
|
||||
process.exit(1)
|
||||
}
|
||||
|
||||
const url = `${BASE_URL}/job/${slug}`
|
||||
|
||||
try {
|
||||
|
||||
@@ -71,3 +71,13 @@ export function writeError(error: string, code: string): void {
|
||||
export function stripHtml(html: string): string {
|
||||
return html.replace(/<[^>]*>/g, "").replace(/\s+/g, " ").trim()
|
||||
}
|
||||
|
||||
export function normalizeSlug(input: string): string | null {
|
||||
const trimmed = input.trim()
|
||||
if (!trimmed) return null
|
||||
const match = trimmed.match(/\/job\/([^/?#]+)/)
|
||||
if (match) return match[1]
|
||||
if (/^[a-zA-Z0-9_-]+$/.test(trimmed)) return trimmed
|
||||
return null
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user