项目作者: shahabganji

项目描述 :
An aurelia plugin handling meta tags
高级语言: TypeScript
项目地址: git://github.com/shahabganji/aurelia-meta.git
创建时间: 2019-02-11T20:26:32Z
项目社区:https://github.com/shahabganji/aurelia-meta

开源协议:MIT License

下载


aurelia-meta

A plugin on top of aurelia-router to handle meta tags of your application, both automatically and manually.

Usage

  1. Install the plugin

    1. yarn install aurelia-meta
  2. Make Aurelia aware of your application

    1. aurelia.use.plugin('aurelia-meta');
  • Bear in mind to use PLATFORM.moduleName if you use webpack
  1. It’s ready to use, just add your meta tags to your routes as a property, no matter whether it’s a parent route or a child one.
  1. config.map([
  2. {
  3. route: '',
  4. name: 'home',
  5. moduleId: PLATFORM.moduleName('./routes/home'),
  6. nav: true,
  7. title: 'Home',
  8. meta: [
  9. {
  10. name: 'home', content: 'This is a Home page'
  11. },
  12. {
  13. property: 'og:title' , content:'Home'
  14. },
  15. {
  16. property: 'og:description' , content:'Aurelia meta is a plugin for Aurelia'
  17. }
  18. ]
  19. },
  20. ...
  21. ]);
  • If you want to add meta tags manually and not necessarily on route changes, use one of these services: Router, AureliaMetaService and use the appropriate methods for your purpose.
  1. import { autoinject } from "aurelia-framework";
  2. import { AureliaMetaService } from "aurelia-meta";
  3. @autoinject()
  4. export class HomeRouteComponent{
  5. message: string = "Hello world!";
  6. constructor(private aureliaMetaService: AureliaMetaService) { }
  7. activate() {
  8. this.aureliaMetaService.addTag({
  9. name: 'author' , content:'Saeed Ganji'
  10. });
  11. }
  12. deactivate() {
  13. this.aureliaMetaService.removeTag({
  14. name: 'author' , content:'Saeed Ganji'
  15. })
  16. }
  17. }
  • Keep in mind that you are responsible to remove tags that you have added manually, the plugin only automatically handles tags defined on the routes.

Build

  • To build the plugin clone this repository and run au build-plugin
  • To run the sample project run npm start