Updated seo

This commit is contained in:
thomashii 2021-08-20 10:33:49 +08:00
parent d440590c2c
commit ee3c087ef5
8 changed files with 66 additions and 72 deletions

View file

@ -1,8 +1,18 @@
# 3.0.0 # Change Log
## 4.0.0
* Updated to use `angel3` packages
* Published with `angel3` prefix
## 3.0.0
* Migrated to support Dart SDK 2.12.x NNBD * Migrated to support Dart SDK 2.12.x NNBD
# 2.0.0 ## 2.0.0
* Angel 2 updates. * Angel 2 updates.
# 1.0.0 ## 1.0.0
* Initial release. * Initial release.

View file

@ -1,6 +1,6 @@
MIT License MIT License (MIT)
Copyright (c) 2018 The Angel Framework Copyright (c) 2021 dukefirehawk.com
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal of this software and associated documentation files (the "Software"), to deal

View file

@ -1,14 +1,16 @@
# seo # Angel3 SEO
[![Pub](https://img.shields.io/pub/v/angel_seo.svg)](https://pub.dartlang.org/packages/angel_seo)
[![build status](https://travis-ci.org/angel-dart/seo.svg?branch=master)](https://travis-ci.org/angel-dart/seo)
Helpers for building SEO-friendly Web pages in Angel. The goal of [![version](https://img.shields.io/badge/pub-v4.0.0-brightgreen)](https://pub.dartlang.org/packages/angel3_seo)
`package:angel_seo` is to speed up perceived client page loads, prevent [![Null Safety](https://img.shields.io/badge/null-safety-brightgreen)](https://dart.dev/null-safety)
the infamous [![Gitter](https://img.shields.io/gitter/room/angel_dart/discussion)](https://gitter.im/angel_dart/discussion)
[flash of unstyled content](https://en.wikipedia.org/wiki/Flash_of_unstyled_content),
and other SEO optimizations that can easily become tedious to perform by hand. [![License](https://img.shields.io/github/license/dukefirehawk/angel)](https://github.com/dukefirehawk/angel/tree/angel3/packages/seo/LICENSE)
Helpers for building SEO-friendly Web pages in Angel. The goal of `package:angel3_seo` is to speed up perceived client page loads, prevent
the infamous [flash of unstyled content](https://en.wikipedia.org/wiki/Flash_of_unstyled_content), and other SEO optimizations that can easily become tedious to perform by hand.
## Disabling inlining per-element ## Disabling inlining per-element
Add a `data-no-inline` attribute to a `link` or `script` to prevent inlining it: Add a `data-no-inline` attribute to a `link` or `script` to prevent inlining it:
```html ```html
@ -16,31 +18,27 @@ Add a `data-no-inline` attribute to a `link` or `script` to prevent inlining it:
``` ```
## `inlineAssets` ## `inlineAssets`
A
[response finalizer](https://angel-dart.gitbook.io/angel/the-basics/request-lifecycle)
that can be used in any application to patch HTML responses, including those sent with
a templating engine like Jael.
In any `text/html` response sent down, `link` and `script` elements that point to internal resources A [response finalizer](https://angel3-docs.dukefirehawk.com/guides/request-lifecycle) that can be used in any application to patch HTML responses, including those sent with a templating engine like Jael3.
will have the contents of said file read, and inlined into the HTML page itself.
In this case, "internal resources" refers to a URI *without* a scheme, i.e. `/site.css` or In any `text/html` response sent down, `link` and `script` elements that point to internal resources will have the contents of said file read, and inlined into the HTML page itself.
`foo/bar/baz.js`.
In this case, "internal resources" refers to a URI *without* a scheme, i.e. `/site.css` or `foo/bar/baz.js`.
```dart ```dart
import 'package:angel_framework/angel_framework.dart'; import 'package:angel3_framework/angel3_framework.dart';
import 'package:angel_seo/angel_seo.dart'; import 'package:angel3_seo/angel3_seo.dart';
import 'package:angel_static/angel_static.dart'; import 'package:angel3_static/angel3_static.dart';
import 'package:file/local.dart'; import 'package:file/local.dart';
main() async { void main() async {
var app = new Angel()..lazyParseBodies = true; var app = Angel()..lazyParseBodies = true;
var fs = const LocalFileSystem(); var fs = const LocalFileSystem();
var http = new AngelHttp(app); var http = AngelHttp(app);
app.responseFinalizers.add(inlineAssets(fs.directory('web'))); app.responseFinalizers.add(inlineAssets(fs.directory('web')));
app.use(() => throw new AngelHttpException.notFound()); app.use(() => throw AngelHttpException.notFound());
var server = await http.startServer('127.0.0.1', 3000); var server = await http.startServer('127.0.0.1', 3000);
print('Listening at http://${server.address.address}:${server.port}'); print('Listening at http://${server.address.address}:${server.port}');
@ -48,24 +46,22 @@ main() async {
``` ```
## `inlineAssetsFromVirtualDirectory` ## `inlineAssetsFromVirtualDirectory`
This function is a simple one; it wraps a `VirtualDirectory` to patch the way it sends
`.html` files.
Produces the same functionality as `inlineAssets`. This function is a simple one; it wraps a `VirtualDirectory` to patch the way it sends `.html` files. Produces the same functionality as `inlineAssets`.
```dart ```dart
import 'package:angel_framework/angel_framework.dart'; import 'package:angel3_framework/angel3_framework.dart';
import 'package:angel_seo/angel_seo.dart'; import 'package:angel3_seo/angel3_seo.dart';
import 'package:angel_static/angel_static.dart'; import 'package:angel3_static/angel3_static.dart';
import 'package:file/local.dart'; import 'package:file/local.dart';
main() async { void main() async {
var app = new Angel()..lazyParseBodies = true; var app = Angel()..lazyParseBodies = true;
var fs = const LocalFileSystem(); var fs = const LocalFileSystem();
var http = new AngelHttp(app); var http = AngelHttp(app);
var vDir = inlineAssets( var vDir = inlineAssets(
new VirtualDirectory( VirtualDirectory(
app, app,
fs, fs,
source: fs.directory('web'), source: fs.directory('web'),
@ -74,7 +70,7 @@ main() async {
app.use(vDir.handleRequest); app.use(vDir.handleRequest);
app.use(() => throw new AngelHttpException.notFound()); app.use(() => throw AngelHttpException.notFound());
var server = await http.startServer('127.0.0.1', 3000); var server = await http.startServer('127.0.0.1', 3000);
print('Listening at http://${server.address.address}:${server.port}'); print('Listening at http://${server.address.address}:${server.port}');

View file

@ -1,8 +1,8 @@
import 'dart:convert'; import 'dart:convert';
import 'package:angel_framework/angel_framework.dart'; import 'package:angel3_framework/angel3_framework.dart';
import 'package:angel_framework/http.dart'; import 'package:angel3_framework/http.dart';
import 'package:angel_seo/angel_seo.dart'; import 'package:angel3_seo/angel3_seo.dart';
import 'package:angel_static/angel_static.dart'; import 'package:angel3_static/angel3_static.dart';
import 'package:file/local.dart'; import 'package:file/local.dart';
import 'package:http_parser/http_parser.dart'; import 'package:http_parser/http_parser.dart';

View file

@ -1,7 +1,7 @@
import 'dart:async'; import 'dart:async';
import 'dart:convert'; import 'dart:convert';
import 'package:angel_framework/angel_framework.dart'; import 'package:angel3_framework/angel3_framework.dart';
import 'package:angel_static/angel_static.dart'; import 'package:angel3_static/angel3_static.dart';
import 'package:file/file.dart'; import 'package:file/file.dart';
import 'package:html/dom.dart' as html; import 'package:html/dom.dart' as html;
import 'package:html/parser.dart' as html; import 'package:html/parser.dart' as html;

View file

@ -1,31 +1,19 @@
name: angel_seo name: angel3_seo
version: 2.0.0 version: 4.0.0
description: Helper infrastructure for building SEO-friendly Web backends in Angel. description: Helper infrastructure for building SEO-friendly Web backends in Angel3.
homepage: https://github.com/angel-dart/seo homepage: https://angel3-framework.web.app/
publish_to: none repository: https://github.com/dukefirehawk/angel/tree/angel3/packages/seo
environment: environment:
sdk: '>=2.12.0 <3.0.0' sdk: '>=2.12.0 <3.0.0'
dependencies: dependencies:
angel_framework: angel3_framework: ^4.1.0
git: angel3_static: ^4.0.0
url: https://github.com/dukefirehawk/angel.git
ref: sdk-2.12.x_nnbd
path: packages/framework
angel_static:
git:
url: https://github.com/dukefirehawk/angel.git
ref: sdk-2.12.x_nnbd
path: packages/static
file: ^6.1.2 file: ^6.1.2
html: ^0.15.0 html: ^0.15.0
http_parser: ^4.0.0 http_parser: ^4.0.0
path: ^1.8.0 path: ^1.8.0
dev_dependencies: dev_dependencies:
angel_test: angel3_test: ^4.0.0
git:
url: https://github.com/dukefirehawk/angel.git
ref: sdk-2.12.x_nnbd
path: packages/test
logging: ^1.0.1 logging: ^1.0.1
test: ^1.17.8 test: ^1.17.8
pedantic: ^1.11.1 pedantic: ^1.11.1

View file

@ -1,7 +1,7 @@
import 'package:angel_framework/angel_framework.dart'; import 'package:angel3_framework/angel3_framework.dart';
import 'package:angel_seo/angel_seo.dart'; import 'package:angel3_seo/angel3_seo.dart';
import 'package:angel_static/angel_static.dart'; import 'package:angel3_static/angel3_static.dart';
import 'package:angel_test/angel_test.dart'; import 'package:angel3_test/angel3_test.dart';
import 'package:file/file.dart'; import 'package:file/file.dart';
import 'package:file/memory.dart'; import 'package:file/memory.dart';
import 'package:html/dom.dart' as html; import 'package:html/dom.dart' as html;