Code Monkey home page Code Monkey logo

nuxt-interpolation's Introduction

nuxt-interpolation

Nuxt.js module as directive for binding every link to catch the click event, and if it's a relative link router will push. For improved security rel="noopener" will be added automatically if target is _blank

โš ๏ธ For Nuxt 3, see here

Setup

Install the module

npm install nuxt-interpolation
# or
yarn add nuxt-interpolation

Register the module

{
  modules: [
    'nuxt-interpolation',
  ]
}

Usage

<div v-html="content" v-interpolation></div>

License

MIT

nuxt-interpolation's People

Contributors

daliborgogic avatar dependabot[bot] avatar mrleblanc101 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

vettndr theleroy

nuxt-interpolation's Issues

nuxt 3 support?

Hi, thank you for the plugin. It does not seem to work with Nuxt 3. I receive following error:

 ERROR  'default' is not exported by node_modules/vue/dist/vue.runtime.esm-bundler.js, imported by virtual:/Users/a/demo-app/.nuxt/interpolation.js
file: virtual:/Users/a/demo-app/.nuxt/interpolation.js:1:0
1: import Vue from 'vue'
   ^
2: 
3: export default ({ app: { router } }) => {


 ERROR  'default' is not exported by node_modules/vue/dist/vue.runtime.esm-bundler.js, imported by virtual:/Users/a/demo-app/.nuxt/interpolation.js

  at error (node_modules/rollup/dist/shared/rollup.js:198:30)
  at Module.error (node_modules/rollup/dist/shared/rollup.js:12521:16)
  at Module.traceVariable (node_modules/rollup/dist/shared/rollup.js:12879:29)
  at ModuleScope.findVariable (node_modules/rollup/dist/shared/rollup.js:11509:39)
  at ReturnValueScope.findVariable (node_modules/rollup/dist/shared/rollup.js:6477:38)
  at ChildScope.findVariable (node_modules/rollup/dist/shared/rollup.js:6477:38)
  at MemberExpression.bind (node_modules/rollup/dist/shared/rollup.js:8706:49)
  at CallExpression.bind (node_modules/rollup/dist/shared/rollup.js:5342:23)
  at CallExpression.bind (node_modules/rollup/dist/shared/rollup.js:8950:15)
  at ExpressionStatement.bind (node_modules/rollup/dist/shared/rollup.js:5342:23)

Any idea how we could workaround it?

Plugin automatically remove extra attributes from rel if target _blank

Hi,
I would say thank you so much for this plugin. This plugin is really cool but I found you have this code:

if (target && target === '_blank') { links[i].setAttribute('rel', 'noopener') }

which is cool but in this case if I have link like this
<a href="..." target="_blank" rel="nofollow noopener">sdf</a>

And the code above will remove everything from rel and replace it with "noopener" but i think we should keep existing rel attributes, your thoughts ? may be we can check if link has already attribute "noopener" skip it ?

TypeError Invalid calling object

I am using nuxt-interpolation in Nuxt 2.3.4 and getting this error Invalid calling object on Edge & IE 11. The exception is showing in my Sentry logs.

Also in Sentry it is showing the lifecycleHook as directive interpolation unbind hook

@nuxtjs/markdownit support

Hi,
I'm using this library with @nuxtjs/markdownit.

It would be very cool if the library automatically set target="blank" attribute if the url is an external link.
In the Storyblok markdown editor I created a text field which contains: [www.example.com](https://www.example.com/)
Am I missing something?

Default behaviour is lost when using ctrl/cmd-click to open page in a new tab

First of all, thank you for the helpful plugin. I'm opening this ticket for a bug we encountered during testing:
Relative links that get transformed with v-interpolation lose their default behaviour when using ctrl/cmd-click to open the page in a new tab. That's an expected user-pattern that's getting lost when using the plugin. It would be nice to keep that default behaviour. Adding a check for event.metaKey when the click occurred could be a solution to fix this issue? (push & preventDefault would not be triggered when cmd or ctrl is used while clicking the link)

Plugin doesn't work for links with nested tags

Hello,
I'm using your plugin and for simple links like
<a href="/mypage">My Link</a>
all works fine. But when I have link with nested tags like
<a href="/mypage"><i>My Link</i></a>
it is handled as base html link but not as nuxt.js router link.

const navigate = event => { const href = event.target.getAttribute('href') ... }
Maybe, replacing event.target with event.currentTarget in this code can solve the issue.

Is nuxt 3 supported?

It does not seem like nuxt 3 is supported yet.
I get the following error when adding "nuxt-interpolation" to the modules part in nuxt.config.ts and running npm run dev:

ERROR  Cannot restart nuxt:  this.addPlugin is not a function
  at module.exports (node_modules\nuxt-interpolation\lib\module.js:4:8)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.