mirror of
https://github.com/jakejarvis/jarv.is.git
synced 2025-07-21 02:21:19 -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
|
||||
const wrapper = document.querySelector("div#meta-hits-counter");
|
||||
|
||||
// page must have both span#meta-hits and canonical URL to enter
|
||||
if (typeof window !== "undefined" && wrapper) {
|
||||
// page must have a div#meta-hits-counter element to continue
|
||||
if (typeof window !== "undefined" && document.querySelector("div#meta-hits-counter")) {
|
||||
// use <link rel="canonical"> to deduce a consistent identifier for this page
|
||||
const canonical = canonicalUrl({
|
||||
normalize: true,
|
||||
@@ -48,7 +45,7 @@ if (typeof window !== "undefined" && wrapper) {
|
||||
});
|
||||
|
||||
// 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)
|
||||
const wrapper = document.querySelector("div#github-cards");
|
||||
|
||||
if (typeof window !== "undefined" && wrapper) {
|
||||
if (typeof window !== "undefined" && document.querySelector("div#github-cards")) {
|
||||
// dayjs plugins: https://day.js.org/docs/en/plugin/loading-into-nodejs
|
||||
dayjs.extend(dayjsAdvancedFormat);
|
||||
dayjs.extend(dayjsLocalizedFormat);
|
||||
@@ -111,5 +109,5 @@ if (typeof window !== "undefined" && wrapper) {
|
||||
// https://en.wikipedia.org/wiki/List_of_tz_database_time_zones#List
|
||||
dayjs.tz.setDefault("America/New_York");
|
||||
|
||||
render(<RepositoryGrid />, wrapper);
|
||||
render(<RepositoryGrid />, document.querySelector("div#github-cards"));
|
||||
}
|
||||
|
Reference in New Issue
Block a user