Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/igorskyflyer/npm-astro-saferesource

๐ŸŽ Adds CSP-compliant inline scripts and styles to Astro! Featured on the official Astro integrations page https://astro.build/integrations/?search=igor.dvlpr ๐ŸŽ 
https://github.com/igorskyflyer/npm-astro-saferesource

astro back-end csp html igorskyflyer inline javascript js script style subresource-integrity ts typescript

Last synced: 1 day ago
JSON representation

๐ŸŽ Adds CSP-compliant inline scripts and styles to Astro! Featured on the official Astro integrations page https://astro.build/integrations/?search=igor.dvlpr ๐ŸŽ 

Awesome Lists containing this project

README

        

๐Ÿ” <SafeResource />



๐ŸŽ Adds CSP-compliant inline scripts and styles to Astro! ๐ŸŽ 








๐Ÿ’– Support further development


I work hard for every project, including this one


and your support means a lot to me!




Consider buying me a coffee. โ˜•


Thank you for supporting my efforts! ๐Ÿ™๐Ÿ˜Š





Donate to igorskyflyer




@igorskyflyer










## ๐Ÿ“ƒ Table of contents

- [Usage](#-usage)
- [Examples](#-examples)
- [Changelog](#-changelog)
- [License](#-license)
- [Related](#-related)
- [Author](#-author)




## ๐Ÿ•ต๐Ÿผ Usage

Install it by executing:

```shell
npm i -D "@igor.dvlpr/astro-saferesource"
```


In order to use it, all you need to do is wrap your existing **inline** `script` or `style` tags with the `` component, i.e.:


`before.astro`
```astro

console.log('Hello World')

```


`after.astro`
```astro
---
import SafeResource from '@igor.dvlpr/astro-saferesource'
---

// <-- do not forget to add is:inline, if not present
console.log('Hello World')

```

and the component will generate the following output:

`after.html`
```astro

console.log('Hello World')

```


> [!NOTE]
> The component outputs a SHA-256 hash.
>


> [!CAUTION]
> Do **NOT** forget to add `is:inline` to the element or else Astro will remove it from the `` component in order to optimize it.
>


> [!TIP]
> The component will log the ***page***, ***type*** of resource (script/style) and the generated ***hashes*** in the console of the IDE.
>

---

## โœจ Examples

`example.astro`
```astro
---
import SafeResource from '@igor.dvlpr/astro-saferesource'
import Layout from '../layouts/Layout.astro'
---




document.addEventListener('DOMContentLoaded', () => {
const easyNav = document.getElementById('easy-nav')
const easyShow = easyNav.getAttribute('data-show')

if (
easyShow === 'whenNeeded' &&
document.documentElement.scrollHeight > window.innerHeight
) {
easyNav.className = 'show'
}
})



.eren-jaeger {
color: red;
}


```

---

## ๐Ÿ“ Changelog

๐Ÿ“‘ The changelog is available here: [CHANGELOG.md](https://github.com/igorskyflyer/npm-astro-saferesource/blob/main/CHANGELOG.md).

---

## ๐Ÿชช License

Licensed under the MIT license which is available here, [MIT license](https://github.com/igorskyflyer/npm-astro-saferesource/blob/main/LICENSE).

---

## ๐Ÿงฌ Related

[@igor.dvlpr/astro-post-excerpt](https://www.npmjs.com/package/@igor.dvlpr/astro-post-excerpt)

> _โญ An Astro component that renders post excerpts for your Astro blog - directly from your Markdown and MDX files. Astro v2+ collections are supported as well! ๐Ÿ’Ž_


[@igor.dvlpr/astro-easynav-button](https://www.npmjs.com/package/@igor.dvlpr/astro-easynav-button)

> _๐Ÿงญ Add an easy-to-use navigational button (jump to top/bottom) to your Astro site. ๐Ÿ”ผ_


[@igor.dvlpr/magic-queryselector](https://www.npmjs.com/package/@igor.dvlpr/magic-queryselector)

> _๐Ÿช„ A TypeScript-types patch for querySelector/querySelectorAll, make them return types you expect them to! ๐Ÿ”ฎ_


[@igor.dvlpr/zep](https://www.npmjs.com/package/@igor.dvlpr/zep)

> _๐Ÿง  Zep is a zero-dependency, efficient debounce module. โฐ_


[@igor.dvlpr/keppo](https://www.npmjs.com/package/@igor.dvlpr/keppo)

> _๐ŸŽก Parse, manage, compare and output SemVer-compatible version numbers. ๐Ÿ›ก_

---


### ๐Ÿ‘จ๐Ÿปโ€๐Ÿ’ป Author
Created by **Igor Dimitrijeviฤ‡** ([*@igorskyflyer*](https://github.com/igorskyflyer/)).