Code Monkey home page Code Monkey logo

eleventy-plugin-link-preview's Introduction

eleventy-plugin-link-preview

npm (scoped) DeepSource DeepSource DeepScan grade npms.io (quality)

Eleventy link preview plugin. Creates an responsive link block and, if necessary, inline css code.

Codepen preview

Usage

Support for Nunjucks and Liquid templates only.

Install via npm

npm install -D @aloskutov/eleventy-plugin-link-preview

Load plugin in .eleventy.js

const linkPreview = require('@aloskutov/eleventy-plugin-link-preview');

module.exports = (eleventyConfig) => {
    eleventyConfig.addPlugin(linkPreview);
};

Insert inline css

Nunjucks

{% linkPreviewCss %}

Liquid

{% linkPreviewCss %}

Insert link

Insert link to 'https://dev.to'

Nunjucks

{% linkPreview "https://dev.to" %}

Liquid

{% linkPreview "https://dev.to" %}

You will get the following HTML code

<div class="link-preview">
  <a class="link-preview__link" href='https://dev.to/'>
    <div class="link-preview__wrapper">
      <div class="link-preview__content">
        <div class="link-preview__title">DEV Community</div>
        <div class="link-preview__description">A constructive and inclusive social network for software developers. With you every step of your journey.</div>
        <div class="link-preview__domain">dev.to</div>
      </div>
      <div class="link-preview__image" style='background-image: url(https://thepracticaldev.s3.amazonaws.com/i/6hqmcjaxbgbon8ydw93z.png);'></div>
    </div>
  </a>
</div>

Custom css

You can use your css based on below code.

.link-preview {
  margin: 0 auto;
  max-width: 1200px;
  padding: 0;
  box-shadow: inset 0 0 0 1px rgb(230 230 230);
}
.link-preview__link {
  text-decoration: none;
}
.link-preview__wrapper {
  display: flex;
  flex-wrap: wrap;
}
.link-preview__content {
  box-sizing: border-box;
  padding: 8px;
  flex: 1 1 270px;
  min-width: 270px;
  height: 168px;
  display: flex;
  align-content: flex-end;
  flex-direction: column;
  justify-content: space-around;
  align-items: flex-start;
}
.link-preview__title {
  font-weight: 600;
  line-height: 24px;
  max-height: 50px;
  font-size: 20px;
  color: hsl(219, 25%, 25%);
  font-family: "PT Serif", serif;
  text-overflow: ellipsis;
  overflow: hidden;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  display: -webkit-box;
}
.link-preview__description {
  margin-top: 8px;
  color: hsl(220, 15%, 30%);
  line-height: 20px;
  font-weight: 400;
  min-width: 240px;
  max-height: 40px;
  text-overflow: ellipsis;
  overflow: hidden;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  display: -webkit-box;
  font-size: 16px;
  font-family: "Open Sans", sans-serif;
}
.link-preview__domain {
  margin-top: 12px;
  font-family: monospace;
  color: hsl(221, 10%, 40%);
}
.link-preview__image {
  display: block;
  padding: 0;
  margin: 0;
  flex: 0 0 clamp(260px, (606px - 100%) * 1000, 100%);
  height: auto;
  background-position: 50% 50%;
  background-size: cover;
  background-origin: border-box;
  aspect-ratio: 2;
  box-shadow: inset 0 0 0 1px rgb(230 230 230);
}

eleventy-plugin-link-preview's People

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

eleventy-plugin-link-preview's Issues

Looks already great but...

Would be great to offer local hosted, optimized images per options etc.

Also it should be possible to pass rel attributes like noopener, noreferrer. nofollow

Cheers

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.