Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow for global api attribute fallback #3

Open
fimion opened this issue Apr 23, 2024 · 1 comment
Open

Allow for global api attribute fallback #3

fimion opened this issue Apr 23, 2024 · 1 comment
Assignees
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@fimion
Copy link

fimion commented Apr 23, 2024

Is your feature request related to a problem? Please describe.

With the current implementation, a user is required to provide an api attribute on each instance of link-peek. If someone needed to change the api call to be a different endpoint across an entire site, this would be a rather labor intensive process to do a search and replace.

Describe the solution you'd like

Add the ability to have a <meta name="link-peek-api" content="https://example.com/?${link}" /> tag defined in the head to specify a fallback value if no api attribute was specified. This will allow each link-peek instance to still call a separate api if needed, but we can also have a fallback defined globally.

Describe alternatives you've considered

An alternative to this would be a static attribute on the LinkPeek class that could be used in the same way. However, the class is not currently exported, and so this would not be usable in a module based import.

@fimion fimion added the enhancement New feature or request label Apr 23, 2024
@daviddarnes
Copy link
Owner

This is a great point @fimion, and something that really bothered me during the development process. I think ideally I would've set up my own API endpoint using cloud functions to provide people with a nice default, however I don't quite have enough experience plus I'd be worried it would get hit so much I'd get hit with a big bill 😅.

Not sure I like the idea of the meta tag, it's a good one but I don't like polluting the HTML anymore than I already am. I'd probably prefer people use something like the following to apply the same API to all instances:

document.querySelectorAll("link-peek").forEach(peek => peek.setAttribute("api", "https://api.microlink.io/?url=${link}"));

Threw a demo together to show it working: https://codepen.io/daviddarnes/pen/yLrZgmv?editors=1011

@daviddarnes daviddarnes added the help wanted Extra attention is needed label Apr 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants