diff --git a/model/source.dart b/model/source.dart index f32f5305..a1bf987c 100644 --- a/model/source.dart +++ b/model/source.dart @@ -63,9 +63,10 @@ class Source { dateFormatLocale = json['dateFormatLocale'] ?? ""; hasCloudflare = json['hasCloudflare'] ?? false; iconUrl = json['iconUrl'] ?? ""; - id = (json['id'] ?? sourceCodeLang == 0 - ? 'mangayomi-"${json['lang'] ?? ""}"."${json['name'] ?? ""}"' - : 'mangayomi-js-"${json['lang'] ?? ""}"."${json['name'] ?? ""}"') + id = (json['id'] ?? + (sourceCodeLang == 0 + ? 'mangayomi-"${json['lang'] ?? ""}"."${json['name'] ?? ""}"' + : 'mangayomi-js-"${json['lang'] ?? ""}"."${json['name'] ?? ""}"')) .hashCode; isFullData = json['isFullData'] ?? false; isManga = json['isManga'] ?? false; diff --git a/source_generator.dart b/source_generator.dart index f2272441..7577dff4 100644 --- a/source_generator.dart +++ b/source_generator.dart @@ -49,19 +49,26 @@ List _searchJsSources(Directory dir) { if (entity is Directory) { sourceList.addAll(_searchJsSources(entity)); } else if (entity is File && entity.path.endsWith('.js')) { - final RegExp regex = RegExp( - r'const\s+mangayomiSources\s*=\s*(\[.*?\]);', + final regex = RegExp(r'const\s+mangayomiSources\s*=\s*(\[.*?\]);', dotAll: true); final defaultSource = Source(); - Match? match = regex.firstMatch(entity.readAsStringSync()); + final match = regex.firstMatch(entity.readAsStringSync()); if (match != null) { - sourceList.addAll((jsonDecode(match.group(1)!) as List) - .map((e) => Source.fromJson(e) - ..sourceCodeLanguage = 1 - ..appMinVerReq = defaultSource.appMinVerReq - ..sourceCodeUrl = - "https://raw.githubusercontent.com/kodjodevf/mangayomi-extensions/$branchName/javascript/${e["pkgPath"] ?? e["pkgName"]}") - .toList()); + for (var sourceJson in jsonDecode(match.group(1)!) as List) { + final langs = sourceJson["langs"] as List?; + final source = Source.fromJson(sourceJson) + ..sourceCodeLanguage = 1 + ..appMinVerReq = defaultSource.appMinVerReq + ..sourceCodeUrl = + "https://raw.githubusercontent.com/kodjodevf/mangayomi-extensions/$branchName/javascript/${sourceJson["pkgPath"] ?? sourceJson["pkgName"]}"; + if (langs?.isNotEmpty ?? false) { + for (var lang in langs!) { + sourceList.add(Source.fromJson(source.toJson())..lang = lang); + } + } else { + sourceList.add(source); + } + } } } }