Use a default path in the editor

When opening a think with no path specified, try some of the most common
paths and show the first one that exists.
This commit is contained in:
Christian Lawson-Perfect 2025-02-20 13:04:31 +00:00
parent 7fd6f8333e
commit 1b6a9956c5

View file

@ -82,6 +82,12 @@ class RemixThinkView(ThinkMixin, generic.UpdateView):
class ThinkView(ThinkMixin, generic.DetailView): class ThinkView(ThinkMixin, generic.DetailView):
template_name = "thinks/think.html" template_name = "thinks/think.html"
default_paths = [
'src/App.elm',
'script.js',
'index.html',
]
def get_context_data(self, *args, **kwargs): def get_context_data(self, *args, **kwargs):
context = super().get_context_data(*args, **kwargs) context = super().get_context_data(*args, **kwargs)
@ -93,6 +99,12 @@ class ThinkView(ThinkMixin, generic.DetailView):
path = think.file_path(strpath) path = think.file_path(strpath)
if path is None:
for f in self.default_paths:
if (root / f).exists():
path = root / f
break
relpath = path.relative_to(root) if path is not None else None relpath = path.relative_to(root) if path is not None else None
if path is None: if path is None: