diff --git a/js/script.js b/js/script.js
index f862988..55b9eb2 100644
--- a/js/script.js
+++ b/js/script.js
@@ -9,12 +9,14 @@ var modalBody = document.getElementById('myModalBody');
var rebuildAndRerunSearch = function() {
rebuildSearchIndex();
- searchOptions();
+ searchOptions('');
};
var docOnload = function(){
+
const urlParams = new URLSearchParams(window.location.search);
const query = urlParams.get('query') ?? '';
+
searchInput.value = query;
searchOptions(query);
@@ -47,6 +49,7 @@ var indexedOptionsTableHeader = document.getElementById('indexedOptionsTableHead
var lastUpdateElement = document.getElementById('lastUpdateElement');
var indexedOptionsTBody = indexedOptionsTable.tBodies[0];
var searchInput = document.getElementById('searchInput');
+var releaseSelect = document.getElementById('releaseSelect');
var optionCountBadge = document.getElementById('optionCountBadge');
var updateLastUpdate = function(lastUpdate) {
@@ -105,21 +108,37 @@ var updateOptionsTable = function(options) {
}
};
+function parseDescription(text){
+
+ text = text.replace(/
]*))/gi ,'<https$1');
+ text = text.replace(/\[\]\(#opt-(\s*([^)]*))/gi ,'$1').replace(/\)/gi,'');
+ //[](#opt-wayland.windowManager.hyprland.plugins)
+ text = text.replace(/\{var\}(\s*([^\n]*))/gi ,'$1').replace(/`/gi,'')
+ text = text.replace(/:::\ \{\.note\}(\s*([^:::]*))/gi ,'$1
').replace(/:::/,'').replace(/\n/g, '
')
+ return text;
+}
+
var expandOption = function(el){
modalTitle.innerHTML = currentSet[el].title;
- var elDesc = "Description
" + currentSet[el].description + "
";
+ //console.log(currentSet[el].description.replace(/:::\ \{\.note\}(\s*([^:::]*))/gi ,'$1
').replace(/:::/,''));
+
+ var elDesc = "Description
" + parseDescription(currentSet[el].description) + "
";
var elType = "Type
" + currentSet[el].type + "
";
- var elNote = ( currentSet[el].note == "" ? "": "Note
" + currentSet[el].note + "
");
+ //var elNote = ( currentSet[el].note == "" ? "": "Note
" + currentSet[el].note + "
");
var elDefault = "Default
" + currentSet[el].default + "
";
var elExample = ( currentSet[el].example == "" ? "" : "Example
" + currentSet[el].example + "
");
- var declared_by_str = currentSet[el].declared_by;
+ //var declared_by_str = currentSet[el].declarations[0].name;
+ //console.log(currentSet[el].declarations[0].name);
+ var declared_by_str;
+ if(currentSet[el].declarations && currentSet[el].declarations.length >0 && currentSet[el].declarations[0].name){
+ declared_by_str = ''+currentSet[el].declarations[0].name.replace(/,'<').replace(/>/,'>')+'';
+ }
var elDeclaredBy = "Declared by
" + declared_by_str+ "
";
- modalBody.innerHTML = elDesc + elNote + elType + elDefault + elExample + elDeclaredBy;
-
+ modalBody.innerHTML = elDesc + elType + elDefault + elExample + elDeclaredBy;
$('#myModal').modal('show')
}
@@ -137,17 +156,19 @@ var updateOptionCountAndTable = function() {
}
};
-var setSearchQueryToUrlParam = function(query) {
+var newUrl = '';
+
+var setSearchQueryToUrlParam = function(query,release) {
const urlParams = new URLSearchParams();
urlParams.set('query', query);
- const newUrl = `${window.location.pathname}?${urlParams.toString()}`;
+ newUrl = `${window.location.pathname}?${urlParams.toString()}&release=${release}`;
window.history.replaceState({}, '', newUrl);
};
var searchOptions = function(query) {
results = search.search(query);
- // Performance optimization: skip ordering if query is a single character
+ // Performance optimization: skip ordering if query is a single character
if (query.length > 1) {
// Split terms by non-alphanumeric chars
const terms = query.split(/[^A-Za-z0-9]/);
@@ -179,12 +200,12 @@ var searchOptions = function(query) {
if (bIndex == -1) return -1;
if (aIndex !== bIndex) return aIndex - bIndex
- // Increment lastIndex by found index and term length, to sort based
+ // Increment lastIndex by found index and term length, to sort based
// on remaining string.
lastIndex += aIndex + term.length;
}
- // Default to alphabetical order otherwise
+ // Default to alphabetical order otherwise
return aConcat.localeCompare(bConcat);
});
}
@@ -196,16 +217,42 @@ const SEARCH_INPUT_DEBOUNCE_MS = 100;
let debounceTimer;
-searchInput.oninput = function() {
- clearTimeout(debounceTimer);
+function newSearch(){
+ clearTimeout(debounceTimer);
debounceTimer = setTimeout(() => {
+
const query = searchInput.value;
- setSearchQueryToUrlParam(query);
+ const release = releaseSelect.selectedOptions[0].value;
+
+ setSearchQueryToUrlParam(query, release);
searchOptions(query);
+
}, SEARCH_INPUT_DEBOUNCE_MS);
+}
+
+searchInput.oninput = function() {
+ newSearch();
};
+releaseSelect.onchange = function(){
+
+ const query = searchInput.value;
+ const release = releaseSelect.selectedOptions[0].value;
+
+ setSearchQueryToUrlParam(query, release);
+
+ //window.location.reload(false);
+
+ window.location.replace(newUrl);
+
+ //newSearch();
+
+ //var release = releaseSelect.selectedOptions[0].value;
+ //xmlhttp.open('GET', 'data/hm-options-'+release+'.json', true);
+ //xmlhttp.send();
+}
+
var updateOptionCount = function(numOptions) {
optionCountBadge.innerText = numOptions + ' options';
};
@@ -237,9 +284,12 @@ xmlhttp.onreadystatechange = function() {
if(searchInput.value.trim() ==""){
updateOptionsTable(allOptions);
}
-
-
}
}
-xmlhttp.open('GET', 'data/options.json', true);
+
+const urlParams = new URLSearchParams(window.location.search);
+const release = urlParams.get('release') ?? 'master';
+document.getElementById('releaseSelect').value = release;
+
+xmlhttp.open('GET', 'data/hm-options-'+release+'.json', true);
xmlhttp.send();
diff --git a/scripts/build_hm_options.sh b/scripts/build_hm_options.sh
new file mode 100755
index 0000000..9f56d4a
--- /dev/null
+++ b/scripts/build_hm_options.sh
@@ -0,0 +1,15 @@
+#!/usr/bin/env sh
+
+# Copyright 2024 Pim Snel 1
- p option_title.upcase
- p declare_arr
- end
- declare_arr.each do | decl |
- decllink = 'https://github.com/nix-community/home-manager/blob/master/' + decl.gsub('','')
- decltext = decl.gsub('<','').gsub('>','')
- option_declared_by_link += ''+decltext+'
'
- end
- elsif ch.text[0..7] == "Example:"
- example = ch.xpath("following-sibling::pre[1]")
- if example.length > 0
- option_example = example.text
- else
- option_example = ch.xpath("code").text
- end
- end
- end
-
- end
-
-# print "---------------------------------------\n"
- print "TITLE:\n#{option_title}\n\n"
- print "DESC:\n#{option_desc}\n\n"
-# print "NOTE:\n#{option_note}\n\n" if option_note != ""
-# print "TYPE:\n#{option_type}\n\n"
-# print "DEFAULT:\n#{option_default}\n\n"
-# print "EXAMPLE:\n#{option_example}\n\n" if option_example != ""
-# print "DECLARED BY:\n#{option_declared_by}\n\n"
-# print "\n"
-#
- outrec = {}
- outrec["title"] = option_title
- outrec["description"] = option_desc
- outrec["note"] = option_note
- outrec["type"] = option_type
- outrec["default"] = option_default
- outrec["example"] = option_example
- outrec["declared_by"] = option_declared_by_link
-
- outarr << outrec
-
-end
-
-
-outobj = {}
-time = Time.new
-outobj["last_update"] = time.utc.strftime("%B %d, %Y at %k:%M UTC")
-outobj["options"] = outarr
-
-File.open("data/options.json","w") do |f|
- f.write(outobj.to_json)
-end
-
-print "Finished parsing home manager options."
diff --git a/scripts/parse_options-json.rb b/scripts/parse_options-json.rb
new file mode 100644
index 0000000..74a240a
--- /dev/null
+++ b/scripts/parse_options-json.rb
@@ -0,0 +1,49 @@
+# Copyright 2024 Pim Snel {});
-mkShell {
- buildInputs = [
- ruby_3_3
- ];
- shellHook = ''
- mkdir -p .nix-gems
- export GEM_HOME=$PWD/.nix-gems
- export GEM_PATH=$GEM_HOME
- export PATH=$GEM_HOME/bin:$PATH
- export PATH=$PWD/bin:$PATH
-
- gem list -i ^bundler$ -v 1.17.3 || gem install bundler --version=1.17.3 --no-document
- bundle
- '';
-}