Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/kherrick/x-postpress

A Web Component used to render articles.
https://github.com/kherrick/x-postpress

custom-elements rest-api typescript web-components wordpress

Last synced: 13 days ago
JSON representation

A Web Component used to render articles.

Awesome Lists containing this project

README

        

# [x-postpress](https://kherrick.github.io/x-postpress/)

A Web Component used to render articles. Content can be slotted or fetched over the network.

## About

* Built with [custom elements](https://developer.mozilla.org/en-US/docs/Web/API/Window/customElements), [CSS custom properties](https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_custom_properties), and [declarative Shadow DOM](https://web.dev/declarative-shadow-dom/) using [TypeScript](https://www.typescriptlang.org/).

## Import

* Add the Web Component to the project (unpkg and npm examples)
1. Load the custom element using a `script` tag:
```html


```
2. Alternatively, add using `npm`:
```bash
npm i x-postpress@3
```
Then import the module from another file:

```javascript
import 'x-postpress'
```

## Use

* Add the tag into the document and style. Content can be slotted, or fetched over the network as [JSON](https://www.json.org/json-en.html) modeled on the [WordPress REST API](https://developer.wordpress.org/rest-api/) [List Posts endpoint](https://developer.wordpress.org/rest-api/reference/posts/#list-posts), as well as preparsed HTML.

```html

x-postpress {
--x-postpress-article-margin: 0 auto 1rem auto;
--x-postpress-h1-font-size: 1.5rem;
}











example-article

Lorem ipsum





// https://web.dev/declarative-shadow-dom/
document.querySelectorAll('template[shadowroot]')
.forEach(template => {
const mode = template.getAttribute('shadowroot');
const shadowRoot = template.parentNode.attachShadow({
mode
});
shadowRoot.appendChild(template.content);
template.remove();
});



```



published on webcomponents.org