Skip to content

Commit

Permalink
fix(modules): refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
yoyurec committed Oct 12, 2022
1 parent 87bf518 commit 22e96f9
Show file tree
Hide file tree
Showing 27 changed files with 240 additions and 234 deletions.
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
</head>
<body>
<div id="app"></div>
<script src="/src/js/awesomeLinks.ts" type="module"></script>
<script src="/src/awesomeLinks.ts" type="module"></script>
</body>
</html>
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
}
},
"dependencies": {
"@logseq/libs": "0.0.8"
"@logseq/libs": "0.0.9"
},
"devDependencies": {
"@semantic-release/changelog": "^6.0.1",
Expand Down
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

67 changes: 67 additions & 0 deletions src/awesomeLinks.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import '@logseq/libs';

import {
globalContext,
doc, body, getDOMContainers,
pageIconsLoad, pageIconsUnload,
nerdFontLoad, nerdFontUnload,
faviconsLoad, faviconsUnload,
journalIconsLoad, journalIconsUnload,
sidebarIconsLoad, sidebarIconsUnload,
initLinksObserver, stopLinksObserver, runLinksObserver, settingsLoad
} from './modules/internal';

const registerPlugin = async () => {
setTimeout(() => {
if (doc.head) {
doc.head.insertAdjacentHTML('beforeend', `<link rel="stylesheet" id="css-awesomeLinks" href="lsp://logseq.io/${globalContext.pluginID}/dist/assets/awesomeLinks.css">`)
}
}, 500);
}

// Main logic runners
const runStuff = async () => {
settingsLoad();
initLinksObserver();
getDOMContainers();
setTimeout(() => {
pageIconsLoad();
faviconsLoad();
journalIconsLoad();
sidebarIconsLoad();
nerdFontLoad();
if (globalContext.pluginConfig?.featureFaviconsEnabled || globalContext.pluginConfig?.featurePageIconsEnabled) {
runLinksObserver();
}
body.classList.add('is-awesomeLinks');
}, 1000)
}
const stopStuff = () => {
pageIconsUnload();
faviconsUnload();
journalIconsUnload();
sidebarIconsUnload();
nerdFontUnload();
stopLinksObserver();
body.classList.remove('is-awesomeLinks');
}

// Main logseq on ready
const main = async () => {
console.log(`AwesomeIcons: plugin loaded`);

globalContext.pluginConfig = logseq.settings;
registerPlugin();

runStuff();

setTimeout(() => {
// Listen plugin unload
logseq.beforeunload(async () => {
stopStuff();
});
}, 2000)

};

logseq.ready(main).catch(null);
91 changes: 0 additions & 91 deletions src/css/awesomeLinks.css

This file was deleted.

102 changes: 0 additions & 102 deletions src/js/awesomeLinks.ts

This file was deleted.

8 changes: 0 additions & 8 deletions src/js/modules/internal.ts

This file was deleted.

File renamed without changes.
10 changes: 7 additions & 3 deletions src/js/modules/favIcons.ts → src/modules/favicons/favIcons.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import globalContext from './globals';
import { doc, body } from './DOMContainers';
import { stopLinksObserver } from './internal';
import { doc, body } from '../DOMContainers';
import {
globalContext,
stopLinksObserver
} from '../internal';

import './favicons.css';

// External links favicons
export const setFavicons = async (extLinkList?: NodeListOf<HTMLAnchorElement>) => {
Expand Down
18 changes: 18 additions & 0 deletions src/modules/favicons/favicons.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
>>> BEGIN: External links
*/
/* hide other themes icons at first */
.is-awesomeLinks-ext .external-link::before,
.is-awesomeLinks-ext .external-link::after {
display: none !important;
}
.is-awesomeLinks-ext .awLinks-link-icon {
display: inline-block;
width: 16px;
height: 16px;
margin: -3px 5px 0 0;
border-radius: 3px;
}
/*
<<<< END: External links
*/
6 changes: 2 additions & 4 deletions src/js/modules/globals.ts → src/modules/globals.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
import { logseq as PL } from '../../../package.json';
import { logseq as PL } from '../../package.json';

type globalContextType = {
pluginID: string;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
[key: string]: any;
}

const globalContext: globalContextType = {
export const globalContext: globalContextType = {
pluginID: PL.id,
pluginConfig: null
};

export default globalContext;
11 changes: 11 additions & 0 deletions src/modules/internal.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export * from './globals';
export * from './DOMContainers';
export * from './settings/settings';
export * from './linksObserver/linksObserver';
export * from './pageIcons/pageIcons';
export * from './pageIcons/queries';
export * from './titleIcon/titleIcon';
export * from './sidebarIcon/sidebarIcon';
export * from './journalIcons/journalIcons';
export * from './favicons/favIcons';
export * from './nerdFont/nerdFont';
16 changes: 16 additions & 0 deletions src/modules/journalIcons/journalIcons.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
>>> BEGIN: Journal icon
*/
body:not(.is-banner-active).is-awesomeLinks-journal .journal-item h1.title::before,
body:not(.is-banner-active).is-awesomeLinks-journal .is-journals h1.title::before {
content: var(--awesomeLinks-journal-icon);
display: inline-block;
margin-right: 0.24em !important;
font-family: var(--icon-font);
text-align: center;
line-height: 1.2em;
width: 1.4em;
}
/*
<<<< END: Journal icon
*/
Loading

0 comments on commit 22e96f9

Please sign in to comment.