Skip to content

Commit

Permalink
131 path based routing on GitHub pages (#132)
Browse files Browse the repository at this point in the history
* 解析js trace,未完成,需要先把URL更为无哈希(hash)的形式,例如 http://localhost:8888/you/flutter_web/pure_dart/execption,你需要切换到使用基于路径的路由(Path-based routing)。

* 解析js trace,未完成,需要先把URL更为无哈希(hash)的形式,例如 http://localhost:8888/you/flutter_web/pure_dart/execption,你需要切换到使用基于路径的路由(Path-based routing)。

* remove mirror.yaml
  • Loading branch information
chen56 authored Apr 19, 2024
1 parent d835936 commit 99d5c2b
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 41 deletions.
24 changes: 0 additions & 24 deletions .github/workflows/mirror.yaml

This file was deleted.

4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ WORKDIR ./you

RUN ./bake install
RUN if [[ "$test" = "on" ]]; then ./bake test ; fi
RUN ./bake flutter build --base-href "/you/flutter_web/"
RUN ./bake flutter_web build
RUN pwd
RUN ls -l

Expand All @@ -24,7 +24,7 @@ FROM nginx:1.23.4 as nginx
# ref:
# https://github.com/nginxinc/docker-nginx/blob/master/mainline

COPY --from=ci /home/flutter/you/notes/flutter_web/build/web /usr/share/nginx/html/you/flutter_web
COPY --from=ci /home/flutter/you/notes/flutter_web/build/web /usr/share/nginx/html/

# The port that your application listens to.
EXPOSE 443
Expand Down
2 changes: 1 addition & 1 deletion bake
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ flutter_web.install() ( flutter_web.run flutter pub get)
flutter_web.clean() ( flutter_web.run flutter clean; rm -rf build;)
flutter_web.upgrade() ( flutter_web.run flutter pub upgrade ;)
flutter_web.build_macos() { flutter_web.run flutter build macos -v --release --tree-shake-icons "$@"; }
flutter_web.build() { flutter_web.run flutter build web -v --release --tree-shake-icons --web-renderer html "$@" ;}
flutter_web.build() { flutter_web.run flutter build web -v --release --tree-shake-icons --web-renderer html --output build/web/you/flutter_web --base-href "/you/flutter_web/" "$@" ;}
flutter_web.build_web_skwasm() { flutter_web.run flutter build web -v --release --tree-shake-icons --web-renderer skwasm "$@" ; }
flutter_web.build_web_canvaskit() { flutter_web.run flutter build web -v --release --tree-shake-icons --web-renderer canvaskit "$@" ; }
flutter_web.dev() { flutter_web.run flutter run --device-id macos "$@"; }
Expand Down
4 changes: 3 additions & 1 deletion notes/flutter_web/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ import 'package:flutter_web/notes.g.dart';
import 'package:you_note_dart/note.dart';
import 'package:flutter_web/note_app.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:flutter_web_plugins/url_strategy.dart';

void main() async {
WidgetsFlutterBinding.ensureInitialized();
usePathUrlStrategy();

NoteSystem noteSystem = await NoteSystem.load(
root: BaseNotes.rootroot,
);
SharedPreferences sharedPreferences = await SharedPreferences.getInstance();
runApp(NoteApp(noteSystem: noteSystem,sharedPreferences:sharedPreferences));
runApp(NoteApp(noteSystem: noteSystem, sharedPreferences: sharedPreferences));
}
5 changes: 3 additions & 2 deletions packages/you_note_dart/lib/src/conventions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ import 'package:path/path.dart' as path;

Conventions conventions = Conventions._();

/// 惯用规则
class Conventions {
Conventions._();

String noteDartAssetPath(String notePath) {
return path.join("lib/notes", notePath, "note.dart");
return path.join("lib/notes", path.relative(notePath, from: "/"), "note.dart");
}

String noteConfAssetPath(String notePath) {
return path.join("lib/notes", notePath, "note.json");
return path.join("lib/notes", path.relative(notePath, from: "/"), "note.json");
}
}
18 changes: 7 additions & 11 deletions packages/you_note_dart/lib/src/note_core.dart
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,9 @@ class NoteRoute {
String get displayName => conf != null ? conf!.displayName : basename;

String get path {
if (isRoot) return "";
if (isRoot) return "/";
var parentPath = parent!.path;
return parentPath == "" ? basename : "$parentPath/$basename";
return parentPath == "/" ? "/$basename" : "$parentPath/$basename";
}

List<NoteRoute> toList({
Expand Down Expand Up @@ -224,11 +224,7 @@ class NoteRoute {
String get confAssetPath => conventions.noteConfAssetPath(path);

Future<NotePage> lazyInit({required NotePageBuilder builder}) async {
return NotePage(
noteRoute: this,
pageBuilder: builder,
conf: conf == null ? null : NoteConf.decode(await rootBundle.loadString(confAssetPath)),
content: await rootBundle.loadString(dartAssetPath));
return NotePage(noteRoute: this, pageBuilder: builder, conf: conf == null ? null : NoteConf.decode(await rootBundle.loadString(confAssetPath)), content: await rootBundle.loadString(dartAssetPath));
}
}
// TODO 这个类设计的比较突兀,
Expand Down Expand Up @@ -386,10 +382,10 @@ class NoteCell extends ChangeNotifier {
cell: this,
specialSources: codeCell.specialNodes
.map((e) => SpecialSource(
codeType: e.nodeType,
codeEntity: CodeEntity(offset: e.offset, end: e.end),
cell: this,
))
codeType: e.nodeType,
codeEntity: CodeEntity(offset: e.offset, end: e.end),
cell: this,
))
.toList(),
);
}
Expand Down
1 change: 1 addition & 0 deletions packages/you_note_dart/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ dev_dependencies:

# for NoteDevTool
stack_trace: ^1.11.0
checks: ^0.3.0

# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec
Expand Down
17 changes: 17 additions & 0 deletions packages/you_note_dart/test/note_route_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import 'package:collection/collection.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:checks/checks.dart';
import 'package:path/path.dart' as path;
void main() {
group("Note path", () {
test("study", () async {
check(path.dirname("/")).equals("/");
check(path.dirname("/a/b")).equals("/a");
check(path.relative("/a/b",from: "/")).equals("a/b");
check(path.dirname("")).equals(".");
check(path.basename("/")).equals("/");
check(path.basename("")).equals("");

});
});
}

0 comments on commit 99d5c2b

Please sign in to comment.