mirror of
https://github.com/jakejarvis/jarv.is.git
synced 2025-07-21 11:41:18 -04:00
fix window !== undefined checks
This commit is contained in:
@@ -32,11 +32,8 @@ const Counter = (props) => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
// don't continue if there isn't a span#meta-hits element on this page
|
// page must have a div#meta-hits-counter element to continue
|
||||||
const wrapper = document.querySelector("div#meta-hits-counter");
|
if (typeof window !== "undefined" && document.querySelector("div#meta-hits-counter")) {
|
||||||
|
|
||||||
// page must have both span#meta-hits and canonical URL to enter
|
|
||||||
if (typeof window !== "undefined" && wrapper) {
|
|
||||||
// use <link rel="canonical"> to deduce a consistent identifier for this page
|
// use <link rel="canonical"> to deduce a consistent identifier for this page
|
||||||
const canonical = canonicalUrl({
|
const canonical = canonicalUrl({
|
||||||
normalize: true,
|
normalize: true,
|
||||||
@@ -48,7 +45,7 @@ if (typeof window !== "undefined" && wrapper) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// get path and strip beginning and ending forward slash
|
// get path and strip beginning and ending forward slash
|
||||||
const slug = new URL(canonical).pathname.replace(/^\/|\/$/g, "");
|
const slug = new URL(canonical).pathname.replace(/^\/|\/$/g, "") || "/";
|
||||||
|
|
||||||
render(<Counter slug={slug} />, wrapper);
|
render(<Counter slug={slug} />, document.querySelector("div#meta-hits-counter"));
|
||||||
}
|
}
|
||||||
|
@@ -99,9 +99,7 @@ const RepositoryCard = (repo) => (
|
|||||||
);
|
);
|
||||||
|
|
||||||
// detect if these cards are wanted on this page (only /projects)
|
// detect if these cards are wanted on this page (only /projects)
|
||||||
const wrapper = document.querySelector("div#github-cards");
|
if (typeof window !== "undefined" && document.querySelector("div#github-cards")) {
|
||||||
|
|
||||||
if (typeof window !== "undefined" && wrapper) {
|
|
||||||
// dayjs plugins: https://day.js.org/docs/en/plugin/loading-into-nodejs
|
// dayjs plugins: https://day.js.org/docs/en/plugin/loading-into-nodejs
|
||||||
dayjs.extend(dayjsAdvancedFormat);
|
dayjs.extend(dayjsAdvancedFormat);
|
||||||
dayjs.extend(dayjsLocalizedFormat);
|
dayjs.extend(dayjsLocalizedFormat);
|
||||||
@@ -111,5 +109,5 @@ if (typeof window !== "undefined" && wrapper) {
|
|||||||
// https://en.wikipedia.org/wiki/List_of_tz_database_time_zones#List
|
// https://en.wikipedia.org/wiki/List_of_tz_database_time_zones#List
|
||||||
dayjs.tz.setDefault("America/New_York");
|
dayjs.tz.setDefault("America/New_York");
|
||||||
|
|
||||||
render(<RepositoryGrid />, wrapper);
|
render(<RepositoryGrid />, document.querySelector("div#github-cards"));
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user