Skip to content

Commit

Permalink
chore: rework js imports (#766)
Browse files Browse the repository at this point in the history
  • Loading branch information
xoxys committed Jan 9, 2024
1 parent ff6e9ed commit 7fa94f3
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 58 deletions.
15 changes: 3 additions & 12 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,13 @@
{
"env": {
"browser": true,
"es6": true,
"amd": true
"es2017": true
},
"extends": ["plugin:prettier/recommended"],
"parser": "@babel/eslint-parser",
"parserOptions": {
"sourceType": "module",
"requireConfigFile": false,
"allowImportExportEverywhere": true
"requireConfigFile": false
},
"plugins": ["prettier"],
"rules": {
"require-await": "warn"
},
"globals": {
"require": false,
"requirejs": false
}
"plugins": ["prettier"]
}
26 changes: 0 additions & 26 deletions src/js/app.js

This file was deleted.

5 changes: 2 additions & 3 deletions src/js/colorTheme.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const Storage = require("store2")
const { TOGGLE_COLOR_THEMES, THEME, COLOR_THEME_AUTO } = require("./config.js")

import Storage from "store2"
import { TOGGLE_COLOR_THEMES, THEME, COLOR_THEME_AUTO } from "./config.js"
;(() => {
applyTheme()
})()
Expand Down
28 changes: 27 additions & 1 deletion src/js/copycode.js → src/js/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,30 @@
export function createCopyButton(highlightDiv) {
import Clipboard from "clipboard"

document.addEventListener("DOMContentLoaded", function (event) {
let clipboard = new Clipboard(".clip")

clipboard.on("success", function (e) {
const trigger = e.trigger

if (trigger.hasAttribute("data-copy-feedback")) {
trigger.classList.add("gdoc-post__codecopy--success", "gdoc-post__codecopy--out")
trigger.querySelector(".gdoc-icon.copy").classList.add("hidden")
trigger.querySelector(".gdoc-icon.check").classList.remove("hidden")

setTimeout(function () {
trigger.classList.remove("gdoc-post__codecopy--success", "gdoc-post__codecopy--out")
trigger.querySelector(".gdoc-icon.copy").classList.remove("hidden")
trigger.querySelector(".gdoc-icon.check").classList.add("hidden")
}, 3000)
}

e.clearSelection()
})

document.querySelectorAll(".highlight").forEach((highlightDiv) => createCopyButton(highlightDiv))
})

function createCopyButton(highlightDiv) {
const button = document.createElement("span")

let codeSelector = "pre > code"
Expand Down
9 changes: 2 additions & 7 deletions src/js/katex.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
import "katex/dist/katex.css"
import renderMathInElement from "katex/dist/contrib/auto-render.mjs"

document.addEventListener("DOMContentLoaded", function () {
import("katex/dist/contrib/auto-render")
.then(({ default: renderMathInElement }) => {
renderMathInElement(document.body)
})
.catch((error) => console.error(error))
})
renderMathInElement(document.body)
6 changes: 3 additions & 3 deletions src/js/mermaid.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const Storage = require("store2")
const { v4: uuidv4 } = require("uuid")
const { COLOR_THEME_DARK, THEME, COLOR_THEME_AUTO } = require("./config.js")
import Storage from "store2"
import { v4 as uuidv4 } from "uuid"
import { COLOR_THEME_DARK, THEME, COLOR_THEME_AUTO } from "./config.js"

import mermaid from "mermaid"

Expand Down
10 changes: 5 additions & 5 deletions src/js/search.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const groupBy = require("lodash/groupBy")
const truncate = require("lodash/truncate")
const { FlexSearch } = require("flexsearch/dist/flexsearch.compact.min")
const { Validator } = require("@cfworker/json-schema")
import groupBy from "lodash/groupBy"
import truncate from "lodash/truncate"
import Document from "flexsearch/dist/module/document"
import { Validator } from "@cfworker/json-schema"

document.addEventListener("DOMContentLoaded", function (event) {
const input = document.querySelector("#gdoc-search-input")
Expand Down Expand Up @@ -66,7 +66,7 @@ function init(input, searchConfig) {
store: ["title", "href", "parent", "description"]
}

const index = new FlexSearch.Document(indexCfg)
const index = new Document(indexCfg)
window.geekdocSearchIndex = index

getJson(dataUrl, function (data) {
Expand Down
3 changes: 2 additions & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var config = {
path.resolve("src", "sass", "mobile.scss"),
path.resolve("src", "sass", "print.scss")
],
main: path.resolve("src", "js", "app.js"),
main: path.resolve("src", "js", "index.js"),
colortheme: path.resolve("src", "js", "colorTheme.js"),
mermaid: path.resolve("src", "js", "mermaid.js"),
katex: [path.resolve("src", "js", "katex.js")].concat(
Expand All @@ -34,6 +34,7 @@ var config = {
watchOptions: {
ignored: ["/exampleSite/", "/node_modules/"]
},
target: ["web", "es2017"],
plugins: [
new CopyPlugin({
patterns: [
Expand Down

0 comments on commit 7fa94f3

Please sign in to comment.