Skip to content

Commit d7121c4

Browse files
committed
update readme and workflow. code lint
1 parent 0cfe090 commit d7121c4

File tree

4 files changed

+36
-54
lines changed

4 files changed

+36
-54
lines changed

.github/workflows/publish.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ jobs:
2222
- name: Build
2323
id: build
2424
run: |
25-
npm i && npm run build
25+
npm ci && npm run build
2626
mkdir ${{ env.PLUGIN_NAME }}
2727
cp README.md package.json icon.png ${{ env.PLUGIN_NAME }}
2828
mv dist ${{ env.PLUGIN_NAME }}
@@ -60,4 +60,4 @@ jobs:
6060
upload_url: ${{ steps.create_release.outputs.upload_url }}
6161
asset_path: ./package.json
6262
asset_name: package.json
63-
asset_content_type: application/json
63+
asset_content_type: application/json

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Automatically fetches the title of a website and wraps it into markdown link format. Also, renders the favicon of the url next to it.
44

5-
# IMAGE
5+
![demo](demo.gif)
66

77
## Credits
88

demo.gif

704 KB
Loading

index.ts

Lines changed: 33 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,6 @@ async function parseBlockForLink(uuid: string) {
7171
let text = content;
7272

7373
const urls = text.match(DEFAULT_SETTINGS.lineRegex);
74-
console.log('---URL', urls);
75-
7674
if (!urls) {
7775
return;
7876
}
@@ -96,22 +94,6 @@ async function parseBlockForLink(uuid: string) {
9694
let blockArray = []; // TODO: this could be a set instead
9795

9896
const main = async () => {
99-
logseq.Editor.registerBlockContextMenuItem('Get link titles', async ({ uuid }) => {
100-
await parseBlockForLink(uuid);
101-
});
102-
103-
logseq.DB.onChanged((e) => {
104-
if (e.txMeta?.outlinerOp === 'insertBlocks') {
105-
blockArray.forEach(parseBlockForLink);
106-
blockArray = [];
107-
} else {
108-
const block = e.blocks[0].uuid;
109-
if (!blockArray.includes(block)) {
110-
blockArray.push(block);
111-
}
112-
}
113-
});
114-
11597
logseq.provideStyle(`
11698
.external-link {
11799
padding: 2px 4px;
@@ -123,7 +105,7 @@ const main = async () => {
123105
text-underline-offset: 2px;
124106
}
125107
.external-link-img {
126-
display: var(--favicons, inline-block);
108+
display: var(--favicons, none);
127109
width: 16px;
128110
height: 16px;
129111
margin: -3px 7px 0 0;
@@ -148,45 +130,45 @@ const main = async () => {
148130
extLinkEl.insertAdjacentElement('afterbegin', fav);
149131
};
150132

151-
// First init run
152-
const setFaviconsOnLoad = () => {
153-
setTimeout(() => {
154-
const extLinkList: NodeListOf<HTMLAnchorElement> = doc.querySelectorAll('.external-link');
155-
for (let i = 0; i < extLinkList.length; i++) {
156-
setFavicon(extLinkList[i]);
157-
}
158-
runExtLinksObserver();
159-
}, 500);
160-
};
161-
162133
// Favicons observer
163-
let extLinksObserver, extLinksObserverConfig;
164-
const initExtLinksObserver = () => {
165-
extLinksObserverConfig = { childList: true, subtree: true };
166-
const extLinksCallback = function(mutationsList, observer) {
167-
for (let i = 0; i < mutationsList.length; i++) {
168-
const addedNode = mutationsList[i].addedNodes[0];
169-
if (addedNode && addedNode.childNodes.length) {
170-
const extLinkList = addedNode.querySelectorAll('.external-link');
171-
if (extLinkList.length) {
172-
extLinksObserver.disconnect();
173-
for (let i = 0; i < extLinkList.length; i++) {
174-
setFavicon(extLinkList[i]);
175-
}
176-
extLinksObserver.observe(appContainer, extLinksObserverConfig);
134+
const extLinksObserverConfig = { childList: true, subtree: true };
135+
const extLinksObserver = new MutationObserver((mutationsList, observer) => {
136+
for (let i = 0; i < mutationsList.length; i++) {
137+
const addedNode = mutationsList[i].addedNodes[0];
138+
if (addedNode && addedNode.childNodes.length) {
139+
const extLinkList = addedNode.querySelectorAll('.external-link');
140+
if (extLinkList.length) {
141+
extLinksObserver.disconnect();
142+
for (let i = 0; i < extLinkList.length; i++) {
143+
setFavicon(extLinkList[i]);
177144
}
145+
extLinksObserver.observe(appContainer, extLinksObserverConfig);
178146
}
179147
}
180-
};
181-
extLinksObserver = new MutationObserver(extLinksCallback);
182-
};
183-
initExtLinksObserver();
148+
}
149+
});
184150

185-
const runExtLinksObserver = () => {
151+
setTimeout(() => {
152+
const extLinkList: NodeListOf<HTMLAnchorElement> = doc.querySelectorAll('.external-link');
153+
extLinkList.forEach(extLink => setFavicon(extLink));
186154
extLinksObserver.observe(appContainer, extLinksObserverConfig);
187-
};
155+
}, 500);
156+
157+
logseq.Editor.registerBlockContextMenuItem('Get link titles', async ({ uuid }) => {
158+
await parseBlockForLink(uuid);
159+
});
188160

189-
setFaviconsOnLoad();
161+
logseq.DB.onChanged(async (e) => {
162+
if (e.txMeta?.outlinerOp === 'insertBlocks') {
163+
await blockArray.forEach(parseBlockForLink);
164+
blockArray = [];
165+
} else {
166+
const block = e.blocks[0].uuid;
167+
if (!blockArray.includes(block)) {
168+
blockArray.push(block);
169+
}
170+
}
171+
});
190172
};
191173

192174
logseq.ready(main).catch(console.error);

0 commit comments

Comments
 (0)