Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
- '*' # Push events to matching any tag format, i.e. 1.0, 20.15.10

env:
PLUGIN_NAME: logseq-plugin-automatic-url-title
PLUGIN_NAME: logseq-plugin-automatic-url-title-fork

jobs:
build:
Expand Down
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
## Logseq Plugin Automatic URL title

#### :warning: Alert: I won't maintain this repo anymore. I consider it complete because it fulfills the requirements that I need. If you need an additional feature or bug to be fixed please feel free to fork the repo and go crazy with it. Thank you :)

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

![demo](demo.gif)
Expand Down
12 changes: 11 additions & 1 deletion index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import '@logseq/libs';

const DEFAULT_REGEX = {
wrappedInCommand: /(\{\{(video)\s*(https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|www\.[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9]+\.[^\s]{2,}|www\.[a-zA-Z0-9]+\.[^\s]{2,})\s*\}\})/gi,
wrappedInCodeTags: /((`|```).*(https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|www\.[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9]+\.[^\s]{2,}|www\.[a-zA-Z0-9]+\.[^\s]{2,}).*(`|```))/gi,
htmlTitleTag: /<title(\s[^>]+)*>([^<]*)<\/title>/,
line: /(https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|www\.[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9]+\.[^\s]{2,}|www\.[a-zA-Z0-9]+\.[^\s]{2,})/gi,
imageExtension: /\.(gif|jpe?g|tiff?|png|webp|bmp|tga|psd|ai)$/i,
Expand Down Expand Up @@ -67,6 +68,15 @@ function isAlreadyFormatted(text, url, urlIndex, formatBeginning) {
return text.slice(urlIndex - 2, urlIndex) === formatBeginning;
}

function isWrappedInCodeTags(text, url) {
const wrappedLinks = text.match(DEFAULT_REGEX.wrappedInCodeTags);
if (!wrappedLinks) {
return false;
}

return wrappedLinks.some(command => command.includes(url));
}

function isWrappedInCommand(text, url) {
const wrappedLinks = text.match(DEFAULT_REGEX.wrappedInCommand);
if (!wrappedLinks) {
Expand Down Expand Up @@ -110,7 +120,7 @@ async function parseBlockForLink(uuid: string) {
for (const url of urls) {
const urlIndex = text.indexOf(url, offset);

if (isAlreadyFormatted(text, url, urlIndex, formatSettings.formatBeginning) || isImage(url) || isWrappedInCommand(text, url)) {
if (isAlreadyFormatted(text, url, urlIndex, formatSettings.formatBeginning) || isImage(url) || isWrappedInCommand(text, url) || isWrappedInCodeTags(text, url)) {
continue;
}

Expand Down