Skip to content

Commit

Permalink
chore(content): move config getter to scraper
Browse files Browse the repository at this point in the history
  • Loading branch information
dan-lovelace committed Sep 17, 2023
1 parent 0db9e6a commit b86683d
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 17 deletions.
11 changes: 0 additions & 11 deletions packages/content/src/lib/config.ts

This file was deleted.

6 changes: 2 additions & 4 deletions packages/content/src/lib/sandbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,9 @@ import {
MESSAGE_ACTIONS,
storageGetByKey,
} from "@hnp/core";
import { getPageData } from "@hnp/scraper";
import { getConfig, getPageData } from "@hnp/scraper";
import { TConfig, TPageDataExtension, TContext } from "@hnp/types";

import { getConfig } from "./config";
import { sendSandboxMessage, startContentListeners } from "./message";

const assetsBaseURL = getAssetURL("img/content");
Expand Down Expand Up @@ -44,8 +43,7 @@ export function handleSandboxLoad() {

export async function renderContent() {
const config = getConfig();
const { view } = config;
const pageData = getPageData(view);
const pageData = getPageData(config.view);
const context = getTemplateContext(config, pageData);
const themeToApply = await getCurrentTheme(config);
const options = await storageGetByKey("OPTIONS");
Expand Down
2 changes: 1 addition & 1 deletion packages/content/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import {
storageSetByKeys,
waitForElement,
} from "@hnp/core";
import { getConfig } from "@hnp/scraper";
import ReactDOM from "react-dom/client";

import App from "./App";
import { getConfig } from "./lib/config";

import "./style/main.scss";

Expand Down
12 changes: 11 additions & 1 deletion packages/scraper/src/lib/parsers/views.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
TComment,
TCommentListItem,
TConfig,
TForm,
TJobListItem,
TLinks,
Expand Down Expand Up @@ -226,6 +227,15 @@ export function getCommentsCount(parent?: Element | null) {
);
}

export function getConfig(): TConfig {
const {
location: { hostname, pathname },
} = window;
const view = getView();

return { hostname, pathname, view };
}

export function getForm(form?: Element | null): TForm {
const action = form?.getAttribute("action") ?? undefined;
const hiddenInputsHTML = pipe(
Expand Down Expand Up @@ -441,7 +451,7 @@ export function getView(): TView {
}

/**
* Non-item routes are easier to infer type since they're 1:1.
* Non-item routes are easier to infer view type since they're 1:1.
*/
const route = matchRoutes(viewRoutes, window.location.pathname);

Expand Down

0 comments on commit b86683d

Please sign in to comment.