Code Monkey home page Code Monkey logo

alpinejs-spa-template's Introduction

AlpineJS SPA template

This is an AlpineJS SPA template with an intuitive folder structure, simple features and included examples.

The template includes the Alpine.js library, structured files with alpinejs-router for dynamic templates based on URLs, and alpinejs-head for meta updates. The design is based on the Tailwind Atlas theme, and it functions as a SPA.

App demo

alpinejs-spa.netlify.app

'alpinejs-spa sceenshot example'

Structure

No Folder Description
1 /components/ - components dir to keep html files and inject it's contenten via x-include directive
1 /content/ - content dir for markdown files to parse and inject as html via x-include.markdown directive
2 /json/ - json dir for json files
2 /pages/ - pages dir for content in html
3 /partials/ - partial elements dir for separate html sections like header, footer, etc.

Custom directives

  • x-include - include custom content like components from file and inject response inside directive's element:
    • default without modifier returns file content as text/html,
    • .markdown modifier to parse markdown file content to html,
  • x-json:value - fetch JSON file or API response and bind it to store named :<value> declared after colon, example:
    • x-json:example="json/example.json" the response from a file will be available in $store.example in template and Alpine.store('example') in JS.

Router templates example

<a x-link href="/hello/world">Hello World</a>

<a x-link href="/somewhere">Load template</a>

<template x-route="/hello/:name">
  <!-- Inner template -->
  <div>Say hello to <span x-text="$router.params.name"></span></div>
</template>

<!-- Separate template file -->
<template x-route="/somewhere" template="/somewhere.html"></template>

Meta updates in the head tag example

<script x-data x-head.json type="application/json">
  {
    "title": "Hello World 👋",
    "meta": [
      {
        "name": "description",
        "content": "How are you today?"
      },
      {
        "name": "theme-color",
        "content": "#00f"
      }
    ],
    "links": [
      {
        "type": "rel",
        "href": "popup.css"
      }
    ],
    "scripts": [
      {
        "src": "popup.js",
        "async": true
      }
    ]
  }
</script>

Disclaimer

It's worth noticing that an SPA mode like this may not be the best for SEO. Perhaps using an SSR wrapper would work better for SEO.

alpinejs-spa-template's People

Contributors

riwert avatar

Stargazers

Komputronika avatar Ahmet İlboga avatar Hassan Kerdash avatar

Watchers

 avatar Ahmet İlboga avatar

alpinejs-spa-template's Issues

A Question

Hi -
I have a question - how would you implement and AUTH check on this ? so checking if the user is logged in and then show something or redirect to login - etc -

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.