|
| 1 | +const DEFAULT_SITE_URL = 'https://www.devsteps.net'; |
| 2 | + |
| 3 | +const rawSiteUrl = |
| 4 | + typeof import.meta !== 'undefined' && import.meta.env && 'PUBLIC_SITE_URL' in import.meta.env |
| 5 | + ? (import.meta.env.PUBLIC_SITE_URL as string) |
| 6 | + : DEFAULT_SITE_URL; |
| 7 | + |
| 8 | +export const siteUrl = (rawSiteUrl || DEFAULT_SITE_URL).replace(/\/+$/, ''); |
| 9 | + |
| 10 | +export const supportedLocales = ['en', 'tr'] as const; |
| 11 | + |
| 12 | +export const toCanonical = (path: string) => { |
| 13 | + const normalized = path.startsWith('/') ? path : `/${path}`; |
| 14 | + return `${siteUrl}${normalized === '/' ? '' : normalized}`; |
| 15 | +}; |
| 16 | + |
| 17 | +export const serializeLdJson = (schema: Record<string, unknown>) => |
| 18 | + JSON.stringify(schema, null, 2); |
| 19 | + |
| 20 | +export const baseOrganizationSchema = { |
| 21 | + '@context': 'https://schema.org', |
| 22 | + '@type': 'Organization', |
| 23 | + name: 'DevSteps', |
| 24 | + url: siteUrl, |
| 25 | + logo: `${siteUrl}/favicon.svg`, |
| 26 | + sameAs: [ |
| 27 | + 'https://github.com/k61b/devsteps', |
| 28 | + 'https://www.reddit.com/r/devsteps/' |
| 29 | + ] |
| 30 | +}; |
| 31 | + |
| 32 | +export const baseWebsiteSchema = { |
| 33 | + '@context': 'https://schema.org', |
| 34 | + '@type': 'WebSite', |
| 35 | + name: 'DevSteps', |
| 36 | + url: siteUrl, |
| 37 | + potentialAction: { |
| 38 | + '@type': 'SearchAction', |
| 39 | + target: `${siteUrl}/browse-courses?query={search_term_string}`, |
| 40 | + 'query-input': 'required name=search_term_string' |
| 41 | + } |
| 42 | +}; |
| 43 | + |
| 44 | +export const buildBreadcrumbSchema = (items: Array<{ name: string; url: string }>) => ({ |
| 45 | + '@context': 'https://schema.org', |
| 46 | + '@type': 'BreadcrumbList', |
| 47 | + itemListElement: items.map((item, index) => ({ |
| 48 | + '@type': 'ListItem', |
| 49 | + position: index + 1, |
| 50 | + name: item.name, |
| 51 | + item: item.url |
| 52 | + })) |
| 53 | +}); |
| 54 | + |
| 55 | +export const buildCourseSchema = (args: { |
| 56 | + name: string; |
| 57 | + description: string; |
| 58 | + url: string; |
| 59 | + providerName: string; |
| 60 | + totalLessons: number; |
| 61 | + durationDays: number; |
| 62 | + language: string; |
| 63 | +}) => ({ |
| 64 | + '@context': 'https://schema.org', |
| 65 | + '@type': 'Course', |
| 66 | + name: args.name, |
| 67 | + description: args.description, |
| 68 | + url: args.url, |
| 69 | + inLanguage: args.language, |
| 70 | + provider: { |
| 71 | + '@type': 'Organization', |
| 72 | + name: args.providerName, |
| 73 | + sameAs: siteUrl |
| 74 | + }, |
| 75 | + numberOfCredits: { |
| 76 | + '@type': 'StructuredValue', |
| 77 | + value: args.totalLessons, |
| 78 | + name: 'Lessons' |
| 79 | + }, |
| 80 | + timeRequired: `P${args.durationDays}D` |
| 81 | +}); |
| 82 | + |
| 83 | +export const buildArticleSchema = (args: { |
| 84 | + title: string; |
| 85 | + description: string; |
| 86 | + url: string; |
| 87 | + dateModified: string; |
| 88 | + datePublished?: string; |
| 89 | + author?: string; |
| 90 | +}) => ({ |
| 91 | + '@context': 'https://schema.org', |
| 92 | + '@type': 'Article', |
| 93 | + headline: args.title, |
| 94 | + description: args.description, |
| 95 | + url: args.url, |
| 96 | + dateModified: args.dateModified, |
| 97 | + datePublished: args.datePublished ?? args.dateModified, |
| 98 | + mainEntityOfPage: args.url, |
| 99 | + author: { |
| 100 | + '@type': 'Organization', |
| 101 | + name: args.author ?? 'DevSteps' |
| 102 | + }, |
| 103 | + publisher: { |
| 104 | + '@type': 'Organization', |
| 105 | + name: 'DevSteps', |
| 106 | + logo: { |
| 107 | + '@type': 'ImageObject', |
| 108 | + url: `${siteUrl}/favicon.svg` |
| 109 | + } |
| 110 | + } |
| 111 | +}); |
0 commit comments