mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-27 01:02:14 +08:00
Allow the default yaml modified key to changed
Some people are using GitJournal to edit Hugo websites, this option is for them as the Hugo front matter uses the 'lastmod' key to indicate when the post was last modified.
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
import 'package:gitjournal/utils/datetime.dart';
|
||||
import 'package:gitjournal/settings.dart';
|
||||
|
||||
import 'note.dart';
|
||||
import 'note_data.dart';
|
||||
@ -9,7 +10,7 @@ abstract class NoteSerializerInterface {
|
||||
}
|
||||
|
||||
class NoteSerializationSettings {
|
||||
String modifiedKey = "modified";
|
||||
String modifiedKey = Settings.instance.yamlModifiedKey;
|
||||
String createdKey = "created";
|
||||
String titleKey = "title";
|
||||
}
|
||||
|
92
lib/screens/settings_note_metadata.dart
Normal file
92
lib/screens/settings_note_metadata.dart
Normal file
@ -0,0 +1,92 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:gitjournal/settings.dart';
|
||||
import 'package:gitjournal/utils/datetime.dart';
|
||||
import 'package:gitjournal/screens/settings_widgets.dart';
|
||||
import 'package:gitjournal/core/note_data_serializers.dart';
|
||||
|
||||
class NoteMetadataSettingsScreen extends StatefulWidget {
|
||||
@override
|
||||
_NoteMetadataSettingsScreenState createState() =>
|
||||
_NoteMetadataSettingsScreenState();
|
||||
}
|
||||
|
||||
class _NoteMetadataSettingsScreenState
|
||||
extends State<NoteMetadataSettingsScreen> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var textTheme = Theme.of(context).textTheme;
|
||||
|
||||
var body = Column(
|
||||
children: <Widget>[
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Text(
|
||||
"Every note has some metadata which is stored in a YAML Header as follows -",
|
||||
style: textTheme.body2,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16.0),
|
||||
NoteMetaDataExample(_buildMap()),
|
||||
const SizedBox(height: 16.0),
|
||||
const Divider(),
|
||||
ListPreference(
|
||||
title: "Modified Field",
|
||||
options: [
|
||||
"modified",
|
||||
"mod",
|
||||
"lastmodified",
|
||||
"lastmod",
|
||||
],
|
||||
currentOption: Settings.instance.yamlModifiedKey,
|
||||
onChange: (String newVal) {
|
||||
setState(() {
|
||||
Settings.instance.yamlModifiedKey = newVal;
|
||||
Settings.instance.save();
|
||||
});
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Note Metadata Settings'),
|
||||
leading: IconButton(
|
||||
icon: const Icon(Icons.arrow_back),
|
||||
onPressed: () {
|
||||
Navigator.of(context).pop();
|
||||
},
|
||||
),
|
||||
),
|
||||
body: body,
|
||||
);
|
||||
}
|
||||
|
||||
Map<String, dynamic> _buildMap() {
|
||||
var created = DateTime.now();
|
||||
return {
|
||||
'created': toIso8601WithTimezone(created),
|
||||
Settings.instance.yamlModifiedKey: toIso8601WithTimezone(created),
|
||||
'title': 'Example Title',
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
class NoteMetaDataExample extends StatelessWidget {
|
||||
final String yamlHeader;
|
||||
|
||||
NoteMetaDataExample(Map<String, dynamic> data)
|
||||
: yamlHeader = MarkdownYAMLSerializer.toYamlHeader(data);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var style = Theme.of(context).textTheme.subhead;
|
||||
style = style.copyWith(fontFamily: "Roboto Mono");
|
||||
|
||||
return Container(
|
||||
color: Colors.grey[200],
|
||||
child: Text(yamlHeader, style: style),
|
||||
padding: const EdgeInsets.all(0),
|
||||
);
|
||||
}
|
||||
}
|
@ -3,6 +3,7 @@ import 'package:gitjournal/settings.dart';
|
||||
import 'package:gitjournal/utils.dart';
|
||||
import 'package:gitjournal/screens/settings_widgets.dart';
|
||||
import 'package:gitjournal/screens/settings_git_remote.dart';
|
||||
import 'package:gitjournal/screens/settings_note_metadata.dart';
|
||||
|
||||
import 'package:dynamic_theme/dynamic_theme.dart';
|
||||
|
||||
@ -168,6 +169,16 @@ class SettingsListState extends State<SettingsList> {
|
||||
setState(() {});
|
||||
},
|
||||
),
|
||||
ListTile(
|
||||
title: const Text("Note Metadata Settings"),
|
||||
subtitle: const Text("Configure how the YAML Metadata is saved"),
|
||||
onTap: () {
|
||||
var route = MaterialPageRoute(
|
||||
builder: (context) => NoteMetadataSettingsScreen(),
|
||||
);
|
||||
Navigator.of(context).push(route);
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 16.0),
|
||||
SettingsHeader("Analytics"),
|
||||
SwitchListTile(
|
||||
|
@ -19,6 +19,7 @@ class Settings {
|
||||
bool collectUsageStatistics = true;
|
||||
bool collectCrashReports = true;
|
||||
|
||||
String yamlModifiedKey = "modified";
|
||||
int version = 0;
|
||||
|
||||
void load(SharedPreferences pref) {
|
||||
@ -36,6 +37,7 @@ class Settings {
|
||||
collectCrashReports =
|
||||
pref.getBool("collectCrashReports") ?? collectCrashReports;
|
||||
|
||||
yamlModifiedKey = pref.getString("yamlModifiedKey") ?? yamlModifiedKey;
|
||||
version = pref.getInt("settingsVersion") ?? version;
|
||||
}
|
||||
|
||||
@ -47,6 +49,7 @@ class Settings {
|
||||
pref.setString("noteFileNameFormat", noteFileNameFormat.toInternalString());
|
||||
pref.setBool("collectUsageStatistics", collectUsageStatistics);
|
||||
pref.setBool("collectCrashReports", collectCrashReports);
|
||||
pref.setString("yamlModifiedKey", yamlModifiedKey);
|
||||
pref.setInt("settingsVersion", version);
|
||||
|
||||
// Shouldn't we check if something has actually changed?
|
||||
@ -63,6 +66,7 @@ class Settings {
|
||||
"noteFileNameFormat": noteFileNameFormat.toInternalString(),
|
||||
"collectUsageStatistics": collectUsageStatistics,
|
||||
"collectCrashReports": collectCrashReports,
|
||||
"yamlModifiedKey": yamlModifiedKey,
|
||||
"version": version,
|
||||
};
|
||||
}
|
||||
|
Reference in New Issue
Block a user