fix(codegen): PUBLIC_URL fallback
This commit is contained in:
@@ -92,6 +92,7 @@ var path = __importStar(require("path"));
|
|||||||
var model_1 = require("../../src/model");
|
var model_1 = require("../../src/model");
|
||||||
var paths_1 = require("../paths");
|
var paths_1 = require("../paths");
|
||||||
var file_1 = require("./file");
|
var file_1 = require("./file");
|
||||||
|
var config_1 = require("../../src/config");
|
||||||
marked_1.marked.setOptions({
|
marked_1.marked.setOptions({
|
||||||
highlight: function (code) { return highlight_js_1.default.highlightAuto(code).value; },
|
highlight: function (code) { return highlight_js_1.default.highlightAuto(code).value; },
|
||||||
});
|
});
|
||||||
@@ -142,11 +143,10 @@ var checkAttributes = function (fileName, attributes) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
var createRevisionsFromFiles = function (fileNames) {
|
var createRevisionsFromFiles = function (fileNames) {
|
||||||
var publicUrl = process.env.PUBLIC_URL;
|
|
||||||
return Promise.all(fileNames.map(function (fileName) {
|
return Promise.all(fileNames.map(function (fileName) {
|
||||||
return (0, fs_extra_1.readFile)(fileName, "utf8").then(function (data) {
|
return (0, fs_extra_1.readFile)(fileName, "utf8").then(function (data) {
|
||||||
var fm = (0, front_matter_1.default)(data);
|
var fm = (0, front_matter_1.default)(data);
|
||||||
var html = (0, marked_1.marked)(fm.body.replace(/\]\(\//g, "](".concat(publicUrl, "/")));
|
var html = (0, marked_1.marked)(fm.body.replace(/\]\(\//g, "](".concat(config_1.publicUrl)));
|
||||||
html = html.replace(/a href="http/g, 'a target="_blank" rel="noopener noreferrer" href="http');
|
html = html.replace(/a href="http/g, 'a target="_blank" rel="noopener noreferrer" href="http');
|
||||||
var attributes = checkAttributes(fileName, fm.attributes);
|
var attributes = checkAttributes(fileName, fm.attributes);
|
||||||
if (attributes) {
|
if (attributes) {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
exports.translate = exports.assetUrl = exports.isMobileViewport = exports.getItemPageNames = exports.radarNameShort = exports.radarName = void 0;
|
exports.translate = exports.assetUrl = exports.publicUrl = exports.isMobileViewport = exports.getItemPageNames = exports.radarNameShort = exports.radarName = void 0;
|
||||||
exports.radarName = process.env.REACT_APP_RADAR_NAME || "AOE Technology Radar";
|
exports.radarName = process.env.REACT_APP_RADAR_NAME || "AOE Technology Radar";
|
||||||
exports.radarNameShort = exports.radarName;
|
exports.radarNameShort = exports.radarName;
|
||||||
var getItemPageNames = function (items) {
|
var getItemPageNames = function (items) {
|
||||||
@@ -17,8 +17,9 @@ function isMobileViewport() {
|
|||||||
return width < 1200;
|
return width < 1200;
|
||||||
}
|
}
|
||||||
exports.isMobileViewport = isMobileViewport;
|
exports.isMobileViewport = isMobileViewport;
|
||||||
|
exports.publicUrl = (process.env.PUBLIC_URL || "").replace(/\/$/, '') + "/";
|
||||||
function assetUrl(file) {
|
function assetUrl(file) {
|
||||||
return process.env.PUBLIC_URL + "/" + file;
|
return exports.publicUrl + file;
|
||||||
}
|
}
|
||||||
exports.assetUrl = assetUrl;
|
exports.assetUrl = assetUrl;
|
||||||
function translate(config, key) {
|
function translate(config, key) {
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import {
|
|||||||
import { appBuild } from "../paths";
|
import { appBuild } from "../paths";
|
||||||
import { getAllMarkdownFiles, radarPath } from "./file";
|
import { getAllMarkdownFiles, radarPath } from "./file";
|
||||||
|
|
||||||
import type { ConfigData } from "../../src/config";
|
import { ConfigData, publicUrl } from "../../src/config";
|
||||||
|
|
||||||
marked.setOptions({
|
marked.setOptions({
|
||||||
highlight: (code: any) => highlight.highlightAuto(code).value,
|
highlight: (code: any) => highlight.highlightAuto(code).value,
|
||||||
@@ -71,12 +71,11 @@ const checkAttributes = (fileName: string, attributes: ItemAttributes) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const createRevisionsFromFiles = (fileNames: string[]) => {
|
const createRevisionsFromFiles = (fileNames: string[]) => {
|
||||||
const publicUrl = process.env.PUBLIC_URL;
|
|
||||||
return Promise.all(
|
return Promise.all(
|
||||||
fileNames.map((fileName) =>
|
fileNames.map((fileName) =>
|
||||||
readFile(fileName, "utf8").then((data) => {
|
readFile(fileName, "utf8").then((data) => {
|
||||||
const fm = frontMatter<ItemAttributes>(data);
|
const fm = frontMatter<ItemAttributes>(data);
|
||||||
let html = marked(fm.body.replace(/\]\(\//g, `](${publicUrl}/`));
|
let html = marked(fm.body.replace(/\]\(\//g, `](${publicUrl}`));
|
||||||
html = html.replace(
|
html = html.replace(
|
||||||
/a href="http/g,
|
/a href="http/g,
|
||||||
'a target="_blank" rel="noopener noreferrer" href="http'
|
'a target="_blank" rel="noopener noreferrer" href="http'
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import {
|
|||||||
useParams,
|
useParams,
|
||||||
} from "react-router-dom";
|
} from "react-router-dom";
|
||||||
|
|
||||||
import { ConfigData } from "../config";
|
import { ConfigData, publicUrl } from "../config";
|
||||||
import { Messages, MessagesProvider } from "../context/MessagesContext";
|
import { Messages, MessagesProvider } from "../context/MessagesContext";
|
||||||
import { useSearchParamState } from "../hooks/use-search-param-state";
|
import { useSearchParamState } from "../hooks/use-search-param-state";
|
||||||
import { Item, filteredOnly, getTags } from "../model";
|
import { Item, filteredOnly, getTags } from "../model";
|
||||||
@@ -90,20 +90,20 @@ interface Data {
|
|||||||
|
|
||||||
export default function App() {
|
export default function App() {
|
||||||
const data = useFetch<Data>(
|
const data = useFetch<Data>(
|
||||||
`${process.env.PUBLIC_URL}/rd.json?${process.env.REACT_APP_BUILDHASH}`
|
`${publicUrl}rd.json?${process.env.REACT_APP_BUILDHASH}`
|
||||||
);
|
);
|
||||||
const messages = useFetch<Messages>(
|
const messages = useFetch<Messages>(
|
||||||
`${process.env.PUBLIC_URL}/messages.json?${process.env.REACT_APP_BUILDHASH}`
|
`${publicUrl}messages.json?${process.env.REACT_APP_BUILDHASH}`
|
||||||
);
|
);
|
||||||
const config = useFetch<ConfigData>(
|
const config = useFetch<ConfigData>(
|
||||||
`${process.env.PUBLIC_URL}/config.json?${process.env.REACT_APP_BUILDHASH}`
|
`${publicUrl}config.json?${process.env.REACT_APP_BUILDHASH}`
|
||||||
);
|
);
|
||||||
|
|
||||||
if (data && config) {
|
if (data && config) {
|
||||||
const { items, releases } = data;
|
const { items, releases } = data;
|
||||||
return (
|
return (
|
||||||
<MessagesProvider messages={messages}>
|
<MessagesProvider messages={messages}>
|
||||||
<BrowserRouter basename={`${process.env.PUBLIC_URL}`}>
|
<BrowserRouter basename={`${publicUrl}`}>
|
||||||
<Routes>
|
<Routes>
|
||||||
<Route
|
<Route
|
||||||
path={"/*"}
|
path={"/*"}
|
||||||
|
|||||||
@@ -38,8 +38,10 @@ export function isMobileViewport() {
|
|||||||
return width < 1200;
|
return width < 1200;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const publicUrl = (process.env.PUBLIC_URL || "").replace(/\/$/, '') + "/";
|
||||||
|
|
||||||
export function assetUrl(file: string) {
|
export function assetUrl(file: string) {
|
||||||
return process.env.PUBLIC_URL + "/" + file;
|
return publicUrl + file;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function translate(config: ConfigData, key: string) {
|
export function translate(config: ConfigData, key: string) {
|
||||||
|
|||||||
Reference in New Issue
Block a user