mirror of
https://hk.gh-proxy.com/https://github.com/NodeBB/nodebb-plugin-emoji.git
synced 2025-10-04 01:20:58 +08:00
feat: use assetBaseUrl instead of forum url
This commit is contained in:
parent
228f03e81b
commit
2f4c18b53e
2 changed files with 24 additions and 17 deletions
|
@ -8,6 +8,7 @@ import controllers from './controllers';
|
|||
|
||||
const nconf = require.main.require('nconf');
|
||||
const buster = require.main.require('./src/meta').config['cache-buster'];
|
||||
const apiControllers = require.main.require('./src/controllers/api');
|
||||
|
||||
export async function init(params: any): Promise<void> {
|
||||
controllers(params);
|
||||
|
@ -18,10 +19,14 @@ export async function init(params: any): Promise<void> {
|
|||
parseNative: boolean;
|
||||
};
|
||||
|
||||
// get assetBaseUrl from core config
|
||||
const { assetBaseUrl } = await apiControllers.loadConfig({ uid: 0, query: { } });
|
||||
|
||||
// initialize parser flags
|
||||
parse.setOptions({
|
||||
ascii: parseAscii,
|
||||
native: parseNative,
|
||||
assetBaseUrl,
|
||||
});
|
||||
|
||||
// always build on startup if in dev mode
|
||||
|
|
36
lib/parse.ts
36
lib/parse.ts
|
@ -5,7 +5,7 @@ import { tableFile, aliasesFile, asciiFile, charactersFile } from './build';
|
|||
const buster = require.main.require('./src/meta').config['cache-buster'];
|
||||
const nconf = require.main.require('nconf');
|
||||
const winston = require.main.require('winston');
|
||||
const url = nconf.get('url');
|
||||
const relative_path = nconf.get('relative_path');
|
||||
|
||||
let metaCache: {
|
||||
table: MetaData.Table;
|
||||
|
@ -72,9 +72,26 @@ const outsideCode = /(^|<\/code>)([^<]*|<(?!code[^>]*>))*(<code[^>]*>|$)/g;
|
|||
const outsideElements = /(<[^>]*>)?([^<>]*)/g;
|
||||
const emojiPattern = /:([a-z\-.+0-9_]+):/g;
|
||||
|
||||
interface ParseOptions {
|
||||
/** whether to parse ascii emoji representations into emoji */
|
||||
ascii?: boolean;
|
||||
native?: boolean;
|
||||
assetBaseUrl: string;
|
||||
}
|
||||
|
||||
const options: ParseOptions = {
|
||||
ascii: false,
|
||||
native: false,
|
||||
assetBaseUrl: `${relative_path}/assets`,
|
||||
};
|
||||
|
||||
export function setOptions(newOptions: ParseOptions): void {
|
||||
Object.assign(options, newOptions);
|
||||
}
|
||||
|
||||
export const buildEmoji = (emoji: StoredEmoji, whole: string): string => {
|
||||
if (emoji.image) {
|
||||
const route = `${url}/plugins/nodebb-plugin-emoji/emoji/${emoji.pack}`;
|
||||
const route = `${options.assetBaseUrl}/plugins/nodebb-plugin-emoji/emoji/${emoji.pack}`;
|
||||
return `<img
|
||||
src="${route}/${emoji.image}?${buster}"
|
||||
class="not-responsive emoji emoji-${emoji.pack} emoji--${emoji.name}"
|
||||
|
@ -113,21 +130,6 @@ const replaceNative = (
|
|||
return char;
|
||||
});
|
||||
|
||||
interface ParseOptions {
|
||||
/** whether to parse ascii emoji representations into emoji */
|
||||
ascii?: boolean;
|
||||
native?: boolean;
|
||||
}
|
||||
|
||||
const options: ParseOptions = {
|
||||
ascii: false,
|
||||
native: false,
|
||||
};
|
||||
|
||||
export function setOptions(newOptions: ParseOptions): void {
|
||||
Object.assign(options, newOptions);
|
||||
}
|
||||
|
||||
const parse = async (content: string): Promise<string> => {
|
||||
if (!content) {
|
||||
return content;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue