Skip to content

Commit

Permalink
Merge pull request #1 from forge42dev/v1.0.0
Browse files Browse the repository at this point in the history
Version 1.0.0
  • Loading branch information
AlemTuzlak authored Jul 23, 2024
2 parents 2171aa3 + c744302 commit 0e242d9
Show file tree
Hide file tree
Showing 61 changed files with 18,178 additions and 13,241 deletions.
472 changes: 431 additions & 41 deletions README.md

Large diffs are not rendered by default.

27,097 changes: 13,945 additions & 13,152 deletions package-lock.json

Large diffs are not rendered by default.

121 changes: 88 additions & 33 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,32 +1,15 @@
{
"name": "open-source-stack",
"name": "seo-tools",
"version": "1.0.0",
"description": "Minimal open-source stack to help you ship an open-source package in TS",
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"types": "./dist/index.d.mts",
"exports": {
".": {
"import": {
"import": "./dist/index.mjs",
"default": "./dist/index.mjs",
"types": "./dist/index.d.mts"
},
"require": {
"import": "./dist/index.js",
"require": "./dist/index.js",
"default": "./dist/index.js",
"types": "./dist/index.d.ts"
}
}
},
"keywords": ["seo", "remix-seo", "seo-tools", "structured-data", "sitemap", "robots", "canonical", "seo-alternate"],
"description": "A set of tools to evolve your SEO strategy to the next level",
"scripts": {
"test": "vitest run",
"test:cov": "vitest run --coverage",
"build": "tsup src/index.ts --dts --format esm,cjs --outDir dist --minify --clean",
"build": "tsup --config tsup.config.ts",
"remix:dev": "npm run dev -w test-apps/remix-vite",
"remix:cjs:dev": "npm run dev -w test-apps/remix-vite-cjs",
"build:dev": "tsup src/index.ts --dts --format cjs,esm --outDir dist",
"build:dev": "tsup --config tsup.dev.config.ts",
"build:dev:watch": "npm run build:dev -- --watch",
"build:dev:cjs:watch": "npm run build:dev -- --watch",
"dev": "npm-run-all -s build:dev -p remix:dev build:dev:watch",
Expand All @@ -37,37 +20,109 @@
"typecheck": "tsc",
"validate": "npm run check && npm run tsc && npm run test"
},
"author": "",
"license": "ISC",
"author": "@forge42dev",
"license": "MIT",
"repository": {
"type": "git",
"url": "git+https://github.com/forge42dev/open-source-stack.git"
"url": "git+https://github.com/forge42dev/seo-tools.git"
},
"bugs": {
"url": "https://github.com/forge42dev/open-source-stack/issues"
"url": "https://github.com/forge42dev/seo-tools/issues"
},
"files": ["dist"],
"workspaces": [".", "test-apps/*"],
"homepage": "https://github.com/forge42dev/open-source-stack#readme",
"homepage": "https://github.com/forge42dev/seo-tools#readme",
"devDependencies": {
"@biomejs/biome": "^1.8.3",
"@types/node": "^20.12.7",
"@vitest/coverage-v8": "^1.5.2",
"happy-dom": "^14.7.1",
"lefthook": "^1.7.2",
"npm-run-all": "^4.1.5",
"tsup": "^8.0.2",
"tsup": "^8.2.2",
"typescript": "^5.4.5",
"vitest": "^1.5.2"
"vitest": "^1.5.2",
"schema-dts": "^1.1.2"
},
"optionalDependencies": {
"@remix-run/server-runtime": ">=2",
"@rollup/rollup-darwin-x64-gnu": "4.18.1",
"@rollup/rollup-darwin-x64-musl": "4.18.1",
"@rollup/rollup-linux-arm64-gnu": "4.18.1",
"@rollup/rollup-linux-x64-gnu": "^4.18.1",
"@rollup/rollup-linux-x64-musl": "^4.18.1",
"@rollup/rollup-win32-arm64-msvc": "4.18.1",
"@rollup/rollup-win32-x64-msvc": "4.18.1",
"@rollup/rollup-win32-x64-musl": "4.18.1",
"@rollup/rollup-darwin-x64-gnu": "4.18.1",
"@rollup/rollup-darwin-x64-musl": "4.18.1",
"@rollup/rollup-linux-arm64-gnu": "4.18.1"
"@rollup/rollup-win32-x64-musl": "4.18.1"
},
"dependencies": {
"url-pattern": "^1.0.3"
},
"exports": {
"./sitemap": {
"import": {
"import": "./dist/sitemap.mjs",
"default": "./dist/sitemap.mjs",
"types": "./dist/sitemap.d.mts"
},
"require": {
"import": "./dist/sitemap.js",
"require": "./dist/sitemap.js",
"default": "./dist/sitemap.js",
"types": "./dist/sitemap.d.ts"
}
},
"./robots": {
"import": {
"import": "./dist/robots.mjs",
"default": "./dist/robots.mjs",
"types": "./dist/robots.d.mts"
},
"require": {
"import": "./dist/robots.js",
"require": "./dist/robots.js",
"default": "./dist/robots.js",
"types": "./dist/robots.d.ts"
}
},
"./canonical": {
"import": {
"import": "./dist/canonical.mjs",
"default": "./dist/canonical.mjs",
"types": "./dist/canonical.d.mts"
},
"require": {
"import": "./dist/canonical.js",
"require": "./dist/canonical.js",
"default": "./dist/canonical.js",
"types": "./dist/canonical.d.ts"
}
},
"./remix/*": {
"import": {
"import": "./dist/remix/*.mjs",
"default": "./dist/remix/*.mjs",
"types": "./dist/remix/*.d.mts"
},
"require": {
"import": "./dist/remix/*.js",
"require": "./dist/remix/*.js",
"default": "./dist/remix/*.js",
"types": "./dist/remix/*.d.ts"
}
},
"./structured-data/*": {
"import": {
"import": "./dist/structured-data/*.mjs",
"default": "./dist/structured-data/*.mjs",
"types": "./dist/structured-data/*.d.mts"
},
"require": {
"import": "./dist/structured-data/*.js",
"require": "./dist/structured-data/*.js",
"default": "./dist/structured-data/*.js",
"types": "./dist/structured-data/*.d.ts"
}
}
}
}
219 changes: 219 additions & 0 deletions src/canonical.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,219 @@
import { generateCanonicalLinks } from "./canonical"

const removeWhitespace = (str: string) => str.replace(/\s/g, "")

describe("generateCanonicalLinks", () => {
it("should return a string of canonical and alternative links properly as a string", () => {
const canonicalLinks = generateCanonicalLinks(
{
url: "/page",
domain: "https://example.com",
alternatives: ["en", "es"],
urlTransformer: ({ url, alternative, domain }) => `${domain}/${alternative}${url}`,
},
false
)
expect(removeWhitespace(canonicalLinks)).toBe(
removeWhitespace(
`<link rel="canonical" href="https://example.com/page">
<link rel="alternate" href="https://example.com/en/page">
<link rel="alternate" href="https://example.com/es/page">`
)
)
})

it("should return links properly as an array of objects", () => {
const canonicalLinks = generateCanonicalLinks({
url: "/page",
domain: "https://example.com",
alternatives: ["en", "es"],
urlTransformer: ({ url, alternative, domain }) => `${domain}/${alternative}${url}`,
})
expect(canonicalLinks).toEqual([
{
tagName: "link",
rel: "canonical",
href: "https://example.com/page",
},
{
tagName: "link",
rel: "alternate",
href: "https://example.com/en/page",
},
{
tagName: "link",
rel: "alternate",
href: "https://example.com/es/page",
},
])
})

it("should return links properly as an array of objects with canonical attributes", () => {
const canonicalLinks = generateCanonicalLinks({
url: "/page",
domain: "https://example.com",
alternatives: ["en", "es"],
urlTransformer: ({ url, alternative, domain }) => `${domain}/${alternative}${url}`,
canonicalAttributes: { test: "test" },
})
expect(canonicalLinks).toEqual([
{
tagName: "link",
rel: "canonical",
href: "https://example.com/page",
test: "test",
},
{
tagName: "link",
rel: "alternate",
href: "https://example.com/en/page",
},
{
tagName: "link",
rel: "alternate",
href: "https://example.com/es/page",
},
])
})

it("should return links properly as an array of objects with alternative attributes", () => {
const canonicalLinks = generateCanonicalLinks({
url: "/page",
domain: "https://example.com",
alternatives: ["en", "es"],
urlTransformer: ({ url, alternative, domain }) => `${domain}/${alternative}${url}`,
altAttributesTransformer: ({ url, alternative, domain }) => ({ test: "test" }),
})
expect(canonicalLinks).toEqual([
{
tagName: "link",
rel: "canonical",
href: "https://example.com/page",
},
{
tagName: "link",
rel: "alternate",
href: "https://example.com/en/page",
test: "test",
},
{
tagName: "link",
rel: "alternate",
href: "https://example.com/es/page",
test: "test",
},
])
})

it("should return links properly as an array of objects with alternative attributes being different based on the function", () => {
const canonicalLinks = generateCanonicalLinks({
url: "/page",
domain: "https://example.com",
alternatives: ["en", "es"],
urlTransformer: ({ url, alternative, domain }) => `${domain}/${alternative}${url}`,
altAttributesTransformer: ({ url, alternative, domain }) => ({ test: `test-${alternative}` }),
})
expect(canonicalLinks).toEqual([
{
tagName: "link",
rel: "canonical",
href: "https://example.com/page",
},
{
tagName: "link",
rel: "alternate",
href: "https://example.com/en/page",
test: "test-en",
},
{
tagName: "link",
rel: "alternate",
href: "https://example.com/es/page",
test: "test-es",
},
])
})

it("should return links properly as an array of objects with canonical and alternative attributes", () => {
const canonicalLinks = generateCanonicalLinks({
url: "/page",
domain: "https://example.com",
alternatives: ["en", "es"],
urlTransformer: ({ url, alternative, domain }) => `${domain}/${alternative}${url}`,
canonicalAttributes: { test: "test" },
altAttributesTransformer: () => ({ test: "test" }),
})
expect(canonicalLinks).toEqual([
{
tagName: "link",
rel: "canonical",
href: "https://example.com/page",
test: "test",
},
{
tagName: "link",
rel: "alternate",
href: "https://example.com/en/page",
test: "test",
},
{
tagName: "link",
rel: "alternate",
href: "https://example.com/es/page",
test: "test",
},
])
})

it("should return links properly as an array of objects with canonical and alternative attributes being different based on the function", () => {
const canonicalLinks = generateCanonicalLinks({
url: "/page",
domain: "https://example.com",
alternatives: ["en", "es"],
urlTransformer: ({ url, alternative, domain }) => `${domain}/${alternative}${url}`,
canonicalAttributes: { test: "test" },
altAttributesTransformer: ({ alternative }) => ({ test: `test-${alternative}` }),
})
expect(canonicalLinks).toEqual([
{
tagName: "link",
rel: "canonical",
href: "https://example.com/page",
test: "test",
},
{
tagName: "link",
rel: "alternate",
href: "https://example.com/en/page",
test: "test-en",
},
{
tagName: "link",
rel: "alternate",
href: "https://example.com/es/page",
test: "test-es",
},
])
})

it("should return links properly as string with canonical and alternative attributes being different based on the function", () => {
const canonicalLinks = generateCanonicalLinks(
{
url: "/page",
domain: "https://example.com",
alternatives: ["en", "es"],
urlTransformer: ({ url, alternative, domain }) => `${domain}/${alternative}${url}`,
canonicalAttributes: { test: "test" },
altAttributesTransformer: ({ alternative }) => ({ test: `test-${alternative}` }),
},
false
)
expect(removeWhitespace(canonicalLinks)).toBe(
removeWhitespace(
`<link rel="canonical" href="https://example.com/page" test="test">
<link rel="alternate" href="https://example.com/en/page" test="test-en">
<link rel="alternate" href="https://example.com/es/page" test="test-es">`
)
)
})
})
Loading

0 comments on commit 0e242d9

Please sign in to comment.