2.0.0
This commit is contained in:
parent
961fd5fc83
commit
baad6bc628
6 changed files with 41 additions and 28 deletions
|
@ -1,2 +1,5 @@
|
||||||
|
# 2.0.0
|
||||||
|
* Angel 2 updates.
|
||||||
|
|
||||||
# 1.0.0
|
# 1.0.0
|
||||||
* Initial release.
|
* Initial release.
|
|
@ -1,3 +1,3 @@
|
||||||
analyzer:
|
analyzer:
|
||||||
strong-mode:
|
strong-mode:
|
||||||
implicit-cast: false
|
implicit-casts: false
|
|
@ -1,11 +1,12 @@
|
||||||
import 'package:angel_framework/angel_framework.dart';
|
import 'package:angel_framework/angel_framework.dart';
|
||||||
|
import 'package:angel_framework/http.dart';
|
||||||
import 'package:angel_seo/angel_seo.dart';
|
import 'package:angel_seo/angel_seo.dart';
|
||||||
import 'package:angel_static/angel_static.dart';
|
import 'package:angel_static/angel_static.dart';
|
||||||
import 'package:dart2_constant/convert.dart';
|
import 'package:dart2_constant/convert.dart';
|
||||||
import 'package:file/local.dart';
|
import 'package:file/local.dart';
|
||||||
|
|
||||||
main() async {
|
main() async {
|
||||||
var app = new Angel()..lazyParseBodies = true;
|
var app = new Angel();
|
||||||
var fs = const LocalFileSystem();
|
var fs = const LocalFileSystem();
|
||||||
var http = new AngelHttp(app);
|
var http = new AngelHttp(app);
|
||||||
|
|
||||||
|
@ -18,7 +19,7 @@ main() async {
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
app.use(vDir.handleRequest);
|
app.fallback(vDir.handleRequest);
|
||||||
|
|
||||||
// OR, just add a finalizer. Note that [VirtualDirectory] *streams* its response,
|
// OR, just add a finalizer. Note that [VirtualDirectory] *streams* its response,
|
||||||
// so a response finalizer does not touch its contents.
|
// so a response finalizer does not touch its contents.
|
||||||
|
@ -26,7 +27,7 @@ main() async {
|
||||||
// You likely won't need to use both; it just depends on your use case.
|
// You likely won't need to use both; it just depends on your use case.
|
||||||
app.responseFinalizers.add(inlineAssets(fs.directory('web')));
|
app.responseFinalizers.add(inlineAssets(fs.directory('web')));
|
||||||
|
|
||||||
app.get('/using_response_buffer', (ResponseContext res) async {
|
app.get('/using_response_buffer', (req, res) async {
|
||||||
var indexHtml = fs.directory('web').childFile('index.html');
|
var indexHtml = fs.directory('web').childFile('index.html');
|
||||||
var contents = await indexHtml.readAsString();
|
var contents = await indexHtml.readAsString();
|
||||||
res
|
res
|
||||||
|
@ -34,7 +35,7 @@ main() async {
|
||||||
..buffer.add(utf8.encode(contents));
|
..buffer.add(utf8.encode(contents));
|
||||||
});
|
});
|
||||||
|
|
||||||
app.use(() => throw new AngelHttpException.notFound());
|
app.fallback((req, res) => throw new 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}');
|
||||||
|
|
|
@ -1,24 +1,23 @@
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
import 'dart:convert';
|
||||||
import 'package:angel_framework/angel_framework.dart';
|
import 'package:angel_framework/angel_framework.dart';
|
||||||
import 'package:angel_static/angel_static.dart';
|
import 'package:angel_static/angel_static.dart';
|
||||||
import 'package:dart2_constant/convert.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;
|
||||||
import 'package:path/path.dart' as p;
|
import 'package:path/path.dart' as p;
|
||||||
|
|
||||||
/// Wraps a `VirtualDirectory` to patch the way it sends
|
/// Inlines assets into buffered responses, resolving paths from an [assetDirectory].
|
||||||
/// `.html` files.
|
|
||||||
///
|
///
|
||||||
/// In any `.html` file sent down, `link` and `script` elements that point to internal resources
|
/// In any `.html` file 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.
|
/// 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 this case, "internal resources" refers to a URI *without* a scheme, i.e. `/site.css` or
|
||||||
/// `foo/bar/baz.js`.
|
/// `foo/bar/baz.js`.
|
||||||
RequestMiddleware inlineAssets(Directory assetDirectory) {
|
RequestHandler inlineAssets(Directory assetDirectory) {
|
||||||
return (req, res) {
|
return (req, res) {
|
||||||
if (res.willCloseItself ||
|
if (!res.isOpen ||
|
||||||
res.streaming ||
|
!res.isBuffered ||
|
||||||
res.contentType.mimeType != 'text/html') {
|
res.contentType.mimeType != 'text/html') {
|
||||||
return new Future<bool>.value(true);
|
return new Future<bool>.value(true);
|
||||||
} else {
|
} else {
|
||||||
|
@ -112,7 +111,7 @@ class _InlineAssets extends VirtualDirectory {
|
||||||
|
|
||||||
res
|
res
|
||||||
..headers['content-type'] = 'text/html; charset=utf8'
|
..headers['content-type'] = 'text/html; charset=utf8'
|
||||||
..buffer.add(utf8.encode(doc.outerHtml));
|
..add(utf8.encode(doc.outerHtml));
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
return await inner.serveFile(file, stat, req, res);
|
return await inner.serveFile(file, stat, req, res);
|
||||||
|
|
18
pubspec.yaml
18
pubspec.yaml
|
@ -1,17 +1,17 @@
|
||||||
name: angel_seo
|
name: angel_seo
|
||||||
description: Helpers for building SEO-friendly Web pages in Angel.
|
description: Helper infrastructure for building SEO-friendly Web backends in Angel.
|
||||||
author: Tobe O <thosakwe@gmail.com>
|
author: Tobe O <thosakwe@gmail.com>
|
||||||
homepage: https://github.com/angel-dart/seo
|
homepage: https://github.com/angel-dart/seo
|
||||||
version: 1.0.0
|
version: 2.0.0
|
||||||
environment:
|
environment:
|
||||||
sdk: ">=1.8.0 <3.0.0"
|
sdk: ">=2.0.0-dev <3.0.0"
|
||||||
dependencies:
|
dependencies:
|
||||||
angel_framework: ^1.0.0-dev
|
angel_framework: ^2.0.0-alpha
|
||||||
angel_static: ^1.3.0
|
angel_static: ^2.0.0-alpha
|
||||||
dart2_constant: ^1.0.0
|
file: ^5.0.0
|
||||||
file: ^2.0.0
|
|
||||||
html: ^0.13.0
|
html: ^0.13.0
|
||||||
path: ^1.0.0
|
path: ^1.0.0
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
angel_test: ^1.0.0
|
angel_test: ^2.0.0-alpha
|
||||||
test: ^0.12.0
|
logging:
|
||||||
|
test: ^1.0.0
|
|
@ -2,22 +2,24 @@ import 'package:angel_framework/angel_framework.dart';
|
||||||
import 'package:angel_seo/angel_seo.dart';
|
import 'package:angel_seo/angel_seo.dart';
|
||||||
import 'package:angel_static/angel_static.dart';
|
import 'package:angel_static/angel_static.dart';
|
||||||
import 'package:angel_test/angel_test.dart';
|
import 'package:angel_test/angel_test.dart';
|
||||||
import 'package:dart2_constant/convert.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;
|
||||||
import 'package:html/parser.dart' as html;
|
import 'package:html/parser.dart' as html;
|
||||||
|
import 'package:http_parser/http_parser.dart';
|
||||||
|
import 'package:logging/logging.dart';
|
||||||
import 'package:test/test.dart';
|
import 'package:test/test.dart';
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
group('inlineAssets', () {
|
group('inlineAssets', () {
|
||||||
group('buffer', inlineAssetsTests((app, dir) {
|
group('buffer', inlineAssetsTests((app, dir) {
|
||||||
app.get('/', (ResponseContext res) async {
|
app.get('/', (req, res) async {
|
||||||
var indexHtml = dir.childFile('index.html');
|
var indexHtml = dir.childFile('index.html');
|
||||||
var contents = await indexHtml.readAsString();
|
var contents = await indexHtml.readAsBytes();
|
||||||
res
|
res
|
||||||
..headers['content-type'] = 'text/html; charset=utf-8'
|
..useBuffer()
|
||||||
..buffer.add(utf8.encode(contents));
|
..contentType = new MediaType.parse('text/html; charset=utf-8')
|
||||||
|
..buffer.add(contents);
|
||||||
});
|
});
|
||||||
|
|
||||||
app.responseFinalizers.add(inlineAssets(dir));
|
app.responseFinalizers.add(inlineAssets(dir));
|
||||||
|
@ -26,7 +28,7 @@ void main() {
|
||||||
group('virtual_directory', inlineAssetsTests((app, dir) {
|
group('virtual_directory', inlineAssetsTests((app, dir) {
|
||||||
var vDir = inlineAssetsFromVirtualDirectory(
|
var vDir = inlineAssetsFromVirtualDirectory(
|
||||||
new VirtualDirectory(app, dir.fileSystem, source: dir));
|
new VirtualDirectory(app, dir.fileSystem, source: dir));
|
||||||
app.use(vDir.handleRequest);
|
app.fallback(vDir.handleRequest);
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -49,6 +51,13 @@ void Function() inlineAssetsTests(InlineAssetTest f) {
|
||||||
var file = fs.file(path);
|
var file = fs.file(path);
|
||||||
await file.writeAsString(contents[path].trim());
|
await file.writeAsString(contents[path].trim());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
app.logger = new Logger('angel_seo')
|
||||||
|
..onRecord.listen((rec) {
|
||||||
|
print(rec);
|
||||||
|
if (rec.error != null) print(rec.error);
|
||||||
|
if (rec.stackTrace != null) print(rec.stackTrace);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
tearDown(() => client.close());
|
tearDown(() => client.close());
|
||||||
|
@ -58,6 +67,7 @@ void Function() inlineAssetsTests(InlineAssetTest f) {
|
||||||
|
|
||||||
setUp(() async {
|
setUp(() async {
|
||||||
var res = await client.get('/', headers: {'accept': 'text/html'});
|
var res = await client.get('/', headers: {'accept': 'text/html'});
|
||||||
|
print(res.body);
|
||||||
doc = html.parse(res.body);
|
doc = html.parse(res.body);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -68,7 +78,7 @@ void Function() inlineAssetsTests(InlineAssetTest f) {
|
||||||
|
|
||||||
test('populates a <style>', () {
|
test('populates a <style>', () {
|
||||||
var style = doc.querySelector('style');
|
var style = doc.querySelector('style');
|
||||||
expect(style.innerHtml.trim(), contents['site.css']);
|
expect(style?.innerHtml?.trim(), contents['site.css']);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('heeds data-no-inline', () {
|
test('heeds data-no-inline', () {
|
||||||
|
|
Loading…
Reference in a new issue