Skip to content

Commit

Permalink
Load theseus.json from local files when in archive mode
Browse files Browse the repository at this point in the history
  • Loading branch information
gingershaped committed Jan 16, 2024
1 parent 83e716f commit 139fd00
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
4 changes: 4 additions & 0 deletions src/latest/scripts/types/files.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ declare module "*.png" {
const url: string;
export = url;
}
declare module "*.json" {
const url: string;
export = url;
}
declare module "*.handlebars.md" {
const content: string;
export = content;
Expand Down
4 changes: 2 additions & 2 deletions src/latest/scripts/util/element-data.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import Fuse from "fuse.js";


export type Element = {
name: string,
symbol: string,
Expand Down Expand Up @@ -44,7 +43,8 @@ type RawElementData = {
version: string,
};

export const ELEMENT_DATA: Promise<ElementData> = fetch("https://vyxal.github.io/Vyxal/theseus.json")
// @ts-expect-error DATA_URI gets replaced by Webpack
export const ELEMENT_DATA: Promise<ElementData> = fetch(DATA_URI)
.then((response) => response.json())
.then((data: RawElementData) => {
return {
Expand Down
11 changes: 6 additions & 5 deletions webpack.config.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const TerserPlugin = require("terser-webpack-plugin");
// const WorkboxPlugin = require('workbox-webpack-plugin');
// const CopyPlugin = require("copy-webpack-plugin");

const LATEST_DATA_URI = "https://vyxal.github.io/Vyxal/theseus.json"

class MonkeyPatchPlugin {
constructor(basePath, enabled) {
Expand All @@ -18,7 +19,7 @@ class MonkeyPatchPlugin {
(compilation, { normalModuleFactory }) => {
normalModuleFactory.hooks.resolve
.tap("MonkeyPatchPlugin", (data) => {
const match = /https?:\/\/vyxal.github.io\/Vyxal\/(.*\.txt)/.exec(data.request)
const match = /https?:\/\/vyxal.github.io\/Vyxal\/(.*\.(txt|json))/.exec(data.request)
if (match != null && this.enabled) {
data.request = path.join("/", this.basePath, match[1])
}
Expand All @@ -39,7 +40,7 @@ module.exports = function (env, argv) {
buildHttp: {
allowedUris: ["https://vyxal.github.io"],
cacheLocation: false,
frozen: false, // the docs can"t tell ME what to do!
frozen: false, // the docs can't tell ME what to do!
}
},
plugins: [
Expand Down Expand Up @@ -83,16 +84,16 @@ module.exports = function (env, argv) {
// exclude: [/style.*\.css$/],
})
),
new webpack.DefinePlugin({
DATA_URI: JSON.stringify(env["vy-archive"] != undefined ? path.join("/", env["vy-archive"], "theseus.json") : LATEST_DATA_URI)
})
// new WorkboxPlugin.InjectManifest({
// swSrc: "./src/latest/js/service.ts",
// exclude: [/\.map$/, /^manifest.*\.js$/, /\.html$/, /style.*\.css$/]
// }),
],
resolve: {
extensions: [".tsx", ".ts", ".js"],
alias: {
"https://vyxal.github.io/Vyxal/ShortDictionary.txt": "https://vyxal.github.io/Vyxal/sus.txt"
}
},
externals: [
function ({ context, request, dependencyType, contextInfo, getResolve }, callback) {
Expand Down

0 comments on commit 139fd00

Please sign in to comment.