Skip to content

Commit

Permalink
feat: use template to generate index.html
Browse files Browse the repository at this point in the history
  • Loading branch information
duncanleo committed Apr 20, 2024
1 parent 72d3ca0 commit 9f09122
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 30 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -177,5 +177,4 @@ public/

dist/
output/
!output/index.html
traces
13 changes: 0 additions & 13 deletions output/index.html

This file was deleted.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"scripts": {
"scrape": "node dist/scraper.js",
"dev:scrape": "ts-node src/scraper.ts",
"build": "tsc -p tsconfig.production.json --outDir dist && cp src/index.html output/",
"build": "tsc -p tsconfig.production.json --outDir dist && cp -R src/templates dist/",
"clean": "rm -Rf dist/**",
"start": "ts-node src/server.ts"
},
Expand Down
14 changes: 0 additions & 14 deletions src/index.html

This file was deleted.

33 changes: 32 additions & 1 deletion src/scraper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@ import 'ts-polyfill/lib/es2019-array';

import puppeteer from 'puppeteer-extra';
import StealthPlugin from 'puppeteer-extra-plugin-stealth';
import pug from 'pug';
import os from 'node:os';
import path from 'node:path';

import * as Sentry from '@sentry/node';

import fs from 'fs';
import fs from 'node:fs';
import controller from './sources/controller';
import generateFeed from './sources/controller/feed';
import { DateTime } from 'luxon';

const { NODE_ENV, SENTRY_DSN } = process.env;

Expand Down Expand Up @@ -51,6 +55,33 @@ async function scraper() {
);

await browser.close();

// Generate index.html

const now = DateTime.now();

const generatedTime = {
isoString: now.toISO(),
displayText: now.toLocaleString(DateTime.DATETIME_FULL),
};

const osInfo = {
platform: os.platform(),
arch: os.arch(),
};

const files = fs.readdirSync('output');

const indexPage = pug.renderFile(
path.join(__dirname, 'templates/index.pug'),
{
files,
osInfo,
generatedTime,
}
);

fs.writeFileSync('output/index.html', indexPage);
}

scraper()
Expand Down
29 changes: 29 additions & 0 deletions src/templates/index.pug
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
doctype html
html(lang='en')
head
title omada-scraper
meta(name="viewport", content="width=device-width, initial-scale=1")

style.
html {
font-family: sans-serif;
}

body
h1 omada-scraper

p Scripts to scrape data for the Omada network system.

section
h2 Generated Files

ul
each val in files
li
a(href=val)= val

p
| Generated 
time(datetime=generatedTime.isoString)= generatedTime.displayText
|  on 
span #{osInfo.platform}/#{osInfo.arch}

0 comments on commit 9f09122

Please sign in to comment.