Skip to content

Commit

Permalink
feat(plugin): add initial mvp
Browse files Browse the repository at this point in the history
  • Loading branch information
bmuenzenmeyer committed Feb 1, 2023
1 parent 860d8a4 commit 4cf5c8f
Show file tree
Hide file tree
Showing 16 changed files with 4,269 additions and 105 deletions.
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# EditorConfig is awesome: https://EditorConfig.org

# top-most EditorConfig file
root = true

[*]
indent_style = tab
indent_size = 2
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = false
insert_final_newline = false
26 changes: 26 additions & 0 deletions .eleventy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const SERVICE_BASE = `https://t1.gstatic.com/faviconV2?client=SOCIAL&type=FAVICON&fallback_opts=TYPE,SIZE,URL&url=%%URL%%&size=%%SIZE%%`

module.exports = (eleventyConfig, options) => {
const defaults = {
size: "1",
}

eleventyConfig.addPairedShortcode("ai", function (content, href, size = 1) {
return `<a href="${href}"><img style="max-height: 1em; position: relative; top: .2em; margin-right: .2em" src="${SERVICE_BASE.replace("%%URL%%", href).replace("%%SIZE%%", size)}"/>${content}</a>`
})

eleventyConfig.addFilter("ai", (href, text) => {
const { size } = {
...defaults,
...options,
}

return `<a href="${href}"><img style="max-height: 1em; position: relative; top: .2em; margin-right: .2em" src="${SERVICE_BASE.replace(
"%%URL%%",
href
).replace("%%SIZE%%", size)}"/>${text}</a>`
})
return {
markdownTemplateEngine: "njk",
}
}
106 changes: 2 additions & 104 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,104 +1,2 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# TypeScript v1 declaration files
typings/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
.env.test

# parcel-bundler cache (https://parceljs.org/)
.cache

# Next.js build output
.next

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and *not* Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port
node_modules
_site
6 changes: 6 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.editorconfig
.prettierrc.js
_includes
_site
tests
index.md
3 changes: 3 additions & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
save-exact=true
audit=false
fund=false
4 changes: 4 additions & 0 deletions .prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
semi: false,
useTabs: true,
}
58 changes: 57 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,57 @@
# eleventy-plugin-inline-link-favicon
# eleventy-plugin-inline-link-favicon

Eleventy shortcodes and filters to add an inline favicon image to a link.

![]()

## Install

```bash
npm install eleventy-plugin-inline-link-favicon
```

## Configuration

Add the plugin to your `.eleventy.js` config file:

```js
const pluginInlineLinkFavicon = require("eleventy-plugin-inline-link-favicon")

module.exports = (eleventyConfig) => {
eleventyConfig.addPlugin(pluginInlineLinkFavicon)
}
```

## Usage

This plugin comes with two mechanisms to create an inline link favicon. You can use a [paired shortcode](https://www.11ty.dev/docs/shortcodes/#paired-shortcodes) or a [filter](https://www.11ty.dev/docs/filters/), both referenced as `ai`. `ai` is short for anchor-image.

## Paired Shortcode

```md
{% ai "https://front-end.social/@brian" %}@brian{% endai %}
```

returns

```html
<a href="https://front-end.social/@brian"
><img
style="max-height: 1em; position: relative; top: .2em; margin-right: .2em"
src="https://t1.gstatic.com/faviconV2?client=SOCIAL&amp;type=FAVICON&amp;fallback_opts=TYPE,SIZE,URL&amp;url=https://front-end.social/@brian&amp;size=1"
/>@brian</a
>
```

## Filter

```md
{{ "https://front-end.social/@brian" | ai("@brian") | safe }}
```

returns the same as above.

## Credits

- Thanks to [5t3ph/eleventy-plugin-template](https://github.com/5t3ph/eleventy-plugin-template) for inspiration
- Thanks to this [blog by Jim Nielsen](https://blog.jim-nielsen.com/2021/displaying-favicons-for-any-domain/) as inspiration.
11 changes: 11 additions & 0 deletions _includes/base.njk
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Test Page - eleventy-plugin-inline-link-favicon</title>
</head>
<body>
{{ content | safe }}
</body>
</html>
35 changes: 35 additions & 0 deletions index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
layout: base.njk
---

# Eleventy Plugin Inline Link Favicon

{%ai "https://github.com/bmuenzenmeyer/eleventy-plugin-inline-link-favicon"%}docs on github{% endai%}

Lorem ipsum dolor sit amet, consectetur adipiscing {% ai "https://brianmuenzenmeyer.com/book/" %}book{% endai %}. Pellentesque sit amet ultricies massa. Donec dolor nisi, mattis blandit justo vel, consectetur mollis nisl. Etiam aliquet tempus arcu, eu tincidunt diam egestas ut. Nulla facilisi. Nullam cursus est eu est consectetur pellentesque. Proin vitae risus luctus, iaculis lacus at, elementum {{ "https://www.washingtonpost.com/" | ai("Washington Post") | safe }}. In hac habitasse platea dictumst. Phasellus non convallis est. Mauris quis diam vestibulum, elementum risus non, hendrerit massa. Integer suscipit nisi id egestas faucibus. Cras maximus erat at augue dictum sodales. Sed pretium sem ac dui ullamcorper, ac venenatis felis varius.

- Paired Shortcode: {% ai "https://www.11ty.dev/docs/shortcodes/#paired-shortcodes" %}paired shortcode docs{% endai %}
- Filter: {{ "https://www.11ty.dev/docs/filters/" | ai("filter docs") | safe }}

## All Syntaxes

- [.njk](/tests/nunjucks/)
- [.liquid](/tests/liquid/)
- [.11ty.js](/tests/javascript/)
- [.md](/tests/markdown)
- [.hbs](/tests/handlebars)

## Default Icon

{% ai "http://example.com" %}example.com{% endai %} - no favicon found

## {{ "https://www.11ty.dev/plugins/" | ai("11ty Plugins") | safe }}

This plugin is one of many cool plugins you should check out!
How does the image scale in a heading?

---

Look, a mock footer usecase!

{% ai "https://front-end.social/@brian" %}@brian{% endai %} | {% ai "https://github.com/bmuenzenmeyer" %}@bmuenzenmeyer{% endai %} | {% ai "https://www.linkedin.com/in/brian-muenzenmeyer-91a77554/" %}Brian Muenzenmeyer{% endai %}
Loading

0 comments on commit 4cf5c8f

Please sign in to comment.