Skip to content

Commit

Permalink
Remove @remix-run/v1-meta (#226)
Browse files Browse the repository at this point in the history
* Remove uses of @remix-run/v1-meta

* Remove @remix-run/v1-meta package

* Remove .npmrc from Dockerfile

* FIx og image for docs
  • Loading branch information
brookslybrand authored Mar 19, 2024
1 parent 70ae0d3 commit a042f14
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 120 deletions.
1 change: 0 additions & 1 deletion .npmrc

This file was deleted.

4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ FROM base as deps

WORKDIR /remixapp

ADD package.json package-lock.json .npmrc ./
ADD package.json package-lock.json ./
RUN npm install --include=dev

# Setup production node_modules
Expand All @@ -24,7 +24,7 @@ FROM base as production-deps
WORKDIR /remixapp

COPY --from=deps /remixapp/node_modules /remixapp/node_modules
ADD package.json package-lock.json .npmrc ./
ADD package.json package-lock.json ./
RUN npm prune --omit=dev

# Build the app
Expand Down
2 changes: 1 addition & 1 deletion app/lib/meta/meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { MetaDescriptor } from "@remix-run/node";

type CustomMetaArgs = {
title: string;
description: string;
description?: string;
siteUrl?: string;
image?: string;
} & { additionalMeta?: MetaDescriptor[] };
Expand Down
2 changes: 1 addition & 1 deletion app/routes/_extras.blog.$slug.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const loader = async ({ params, request }: LoaderFunctionArgs) => {
};

export const headers: HeadersFunction = ({ loaderHeaders }) => {
// Inherit the caching headers from the loader so we do't cache 404s
// Inherit the caching headers from the loader so we don't cache 404s
return loaderHeaders;
};

Expand Down
2 changes: 1 addition & 1 deletion app/routes/_marketing._index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export const loader = async ({ request }: LoaderFunctionArgs) => {
};

export const headers: HeadersFunction = ({ loaderHeaders }) => {
// Inherit the caching headers from the loader so we do't cache 404s
// Inherit the caching headers from the loader so we don't cache 404s
return loaderHeaders;
};

Expand Down
9 changes: 4 additions & 5 deletions app/routes/_marketing.newsletter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ import { useNavigation, useActionData } from "@remix-run/react";
import type { MetaFunction } from "@remix-run/react";
import { useEffect, useRef } from "react";
import { Subscribe } from "~/ui/subscribe";
import { metaV1 } from "@remix-run/v1-meta";
import type { action } from "~/routes/[_]actions.newsletter";

export const meta: MetaFunction = (args) => {
return metaV1(args, {
export const meta: MetaFunction = () => [
{
title: "Remix Newsletter",
});
};
},
];

export default function Newsletter() {
let navigation = useNavigation();
Expand Down
78 changes: 32 additions & 46 deletions app/routes/docs.$lang.$ref.$.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import type {
SerializeFrom,
} from "@remix-run/node";
import type { MetaFunction } from "@remix-run/react";
import { metaV1, getMatchesData } from "@remix-run/v1-meta";
import { CACHE_CONTROL, handleRedirects } from "~/lib/http.server";
import invariant from "tiny-invariant";
import type { Doc } from "~/lib/gh-docs";
Expand All @@ -24,10 +23,13 @@ import cx from "clsx";
import { useDelegatedReactRouterLinks } from "~/ui/delegate-links";
import type { loader as docsLayoutLoader } from "~/routes/docs.$lang.$ref";
import type { loader as rootLoader } from "~/root";
import { getMeta } from "~/lib/meta";

export async function loader({ params, request }: LoaderFunctionArgs) {
let url = new URL(request.url);
let pageUrl = url.protocol + "//" + url.host + url.pathname;
let baseUrl = url.protocol + "//" + url.host;
let siteUrl = baseUrl + url.pathname;
let ogImageUrl = baseUrl + "/img/og.1.jpg";
invariant(params.ref, "expected `ref` params");
try {
let slug = params["*"]?.endsWith("/changelog")
Expand All @@ -36,7 +38,7 @@ export async function loader({ params, request }: LoaderFunctionArgs) {
let doc = await getRepoDoc(params.ref, slug);
if (!doc) throw null;
return json(
{ doc, pageUrl },
{ doc, siteUrl, ogImageUrl },
{ headers: { "Cache-Control": CACHE_CONTROL.doc } },
);
} catch (_) {
Expand All @@ -51,7 +53,7 @@ export async function loader({ params, request }: LoaderFunctionArgs) {
}

export const headers: HeadersFunction = ({ loaderHeaders }) => {
// Inherit the caching headers from the loader so we do't cache 404s
// Inherit the caching headers from the loader so we don't cache 404s
let headers = new Headers(loaderHeaders);
headers.set("Vary", "Cookie");
return headers;
Expand All @@ -68,12 +70,18 @@ type MatchLoaders = {
export const meta: MetaFunction<Loader, MatchLoaders> = (args) => {
let { data } = args;

let matchesData = getMatchesData<Loader, MatchLoaders>(args);
let parentData = matchesData[LAYOUT_LOADER_KEY];
let parentData = args.matches.find(
(match) => match.id === LAYOUT_LOADER_KEY,
)?.data;
let rootData = args.matches.find((match) => match.id === "root")?.data;
invariant(
parentData && "latestVersion" in parentData,
"No parent data found",
);
invariant(rootData && "isProductionHost" in rootData, "No root data found");

if (!data) {
return metaV1(args, {
title: "Not Found",
});
return [{ title: "Not Found" }];
}

let { doc } = data;
Expand All @@ -95,48 +103,26 @@ export const meta: MetaFunction<Loader, MatchLoaders> = (args) => {
let isMainBranch = currentGitHubRef === releaseBranch;

let robots =
matchesData.root.isProductionHost && isMainBranch
rootData.isProductionHost && isMainBranch
? "index,follow"
: "noindex,nofollow";

let pageUrl = data.pageUrl;

// TODO: add more + better SEO stuff
// let url = new URL(data.pageUrl);
// let siteUrl = url.protocol + "//" + url.host;
// let ogImage = `${siteUrl}/image.jpg`;
// let ogImageAlt = title;
// let twitterImage = ogImage;
// let twitterImageAlt = title;
// let description: 'some description';
let { siteUrl, ogImageUrl } = data;

return metaV1(args, {
return getMeta({
title: `${title} | Remix`,
// description,

"og:title": title,
// "og:description": description,
"og:url": pageUrl,
"og:type": "article",
"og:site_name": "Remix",
// "og:image": ogImage,
// "og:image:alt": ogImageAlt,
// "og:image:secure_url": ogImage,
// "og:image:type": "image/jpeg",
// "og:image:width": "1200",
// "og:image:height": "630",
// "og:locale": "en_US",

"twitter:title": title,
"twitter:site": "@remix_run",
"twitter:creator": "@remix_run",
// "twitter:image": twitterImage,
// "twitter:image:alt": twitterImageAlt,
// "twitter:description": description,
// "twitter:card": "summary",

robots: robots,
googlebot: robots,
// TODO: add a description
// let description: 'some description';
siteUrl,
image: ogImageUrl,
additionalMeta: [
{ name: "og:type", content: "article" },
{ name: "og:site_name", content: "Remix" },
{ name: "docsearch:language", content: args.params.lang || "en" },
{ name: "docsearch:version", content: args.params.ref || "v1" },
{ name: "robots", content: robots },
{ name: "googlebot", content: robots },
],
});
};

Expand Down
9 changes: 0 additions & 9 deletions app/routes/docs.$lang.$ref.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,8 @@ import {
useResolvedPath,
matchPath,
} from "@remix-run/react";
import type { MetaFunction } from "@remix-run/react";
import { json, redirect } from "@remix-run/node";
import type { LoaderFunctionArgs, HeadersFunction } from "@remix-run/node";
import { metaV1 } from "@remix-run/v1-meta";
import cx from "clsx";
import { DocSearch } from "~/ui/docsearch";
import { useNavigate } from "react-router-dom";
Expand Down Expand Up @@ -75,13 +73,6 @@ export const loader = async ({ params }: LoaderFunctionArgs) => {
});
};

export const meta: MetaFunction<typeof loader> = (args) => {
return metaV1(args, {
"docsearch:language": args.params.lang || "en",
"docsearch:version": args.params.ref || "v1",
});
};

export const headers: HeadersFunction = () => {
return {
"Cache-Control": CACHE_CONTROL.doc,
Expand Down
53 changes: 0 additions & 53 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
"@remix-run/express": "0.0.0-experimental-9989381a2",
"@remix-run/node": "0.0.0-experimental-9989381a2",
"@remix-run/react": "0.0.0-experimental-9989381a2",
"@remix-run/v1-meta": "0.1.3",
"@tailwindcss/aspect-ratio": "^0.4.2",
"cheerio": "^1.0.0-rc.12",
"clsx": "^2.1.0",
Expand Down

0 comments on commit a042f14

Please sign in to comment.