From a64548630c531d7a7960f5e83d727a8bd423deaa Mon Sep 17 00:00:00 2001 From: Joe Mou Date: Fri, 23 Jan 2026 01:07:48 -0500 Subject: Refactor template layout --- cgithub/views/blob.eta | 38 ++------------------------------ cgithub/views/layout.eta | 41 +++++++++++++++++++++++++++++++++++ cgithub/views/tree.eta | 56 +++++++++++++----------------------------------- 3 files changed, 58 insertions(+), 77 deletions(-) create mode 100644 cgithub/views/layout.eta (limited to 'cgithub') diff --git a/cgithub/views/blob.eta b/cgithub/views/blob.eta index d3c6a56..566f5b0 100644 --- a/cgithub/views/blob.eta +++ b/cgithub/views/blob.eta @@ -1,37 +1,3 @@ - - - - - <%= it.repo.owner %>/<%= it.repo.name %> - <%= it.path %> - - - -
-

<%= it.repo.owner %>/<%= it.repo.name %>

-
branch: <%= it.branch %>
-
- path: root<% - const pathParts = it.path.split('/').filter(p => p); - let currentPath = ''; - for (let i = 0; i < pathParts.length; i++) { - const part = pathParts[i]; - currentPath += (currentPath ? '/' : '') + part; - const isLast = i === pathParts.length - 1; - if (isLast) { - %>/<%= part %><% - } else { - %>/<%= part %><% - } - } %> -
- <% if (it.language) { %> -
language: <%= it.language %>
- <% } %> -
size: <%= it.size %> bytes
-
+<% layout("./layout") %> -
<%= it.rawContent %>
- - - - +
<%= it.rawContent %>
diff --git a/cgithub/views/layout.eta b/cgithub/views/layout.eta new file mode 100644 index 0000000..8e5d9d9 --- /dev/null +++ b/cgithub/views/layout.eta @@ -0,0 +1,41 @@ + + + + + <%= it.repo.owner %>/<%= it.repo.name %> - <%= it.path || 'root' %> + + + +
+

<%= it.repo.owner %>/<%= it.repo.name %>

+
branch: <%= it.branch %>
+ <% if (it.path) { %> +
+ path: root<% + const pathParts = it.path.split('/').filter(p => p); + let currentPath = ''; + for (let i = 0; i < pathParts.length; i++) { + const part = pathParts[i]; + currentPath += (currentPath ? '/' : '') + part; + const isLast = i === pathParts.length - 1; + if (isLast) { + %>/<%= part %><% + } else { + %>/<%= part %><% + } + } %> +
+ <% } %> + <% if (it.language) { %> +
language: <%= it.language %>
+ <% } %> + <% if (it.size !== undefined) { %> +
size: <%= it.size %> bytes
+ <% } %> +
+ + <%~ it.body %> + + + + diff --git a/cgithub/views/tree.eta b/cgithub/views/tree.eta index b49668d..911b7ee 100644 --- a/cgithub/views/tree.eta +++ b/cgithub/views/tree.eta @@ -1,42 +1,16 @@ - - - - - <%= it.repo.owner %>/<%= it.repo.name %> - <%= it.path || 'root' %> - - - -
-

<%= it.repo.owner %>/<%= it.repo.name %>

-
branch: <%= it.branch %>
- <% if (it.path) { %> -
- path: root<% - const pathParts = it.path.split('/').filter(p => p); - let currentPath = ''; - for (const part of pathParts) { - currentPath += (currentPath ? '/' : '') + part; - %>/<%= part %><% - } %> -
- <% } %> -
+<% layout("./layout") %> - - <% for (const item of it.items) { %> - - - - <% } %> -
- <%= item.contentType === 'directory' ? '📁' : '📄' %> - <% if (item.contentType === 'directory') { %> - <%= item.name %> - <% } else { %> - <%= item.name %> - <% } %> -
- - - - + + <% for (const item of it.items) { %> + + + + <% } %> +
+ <%= item.contentType === 'directory' ? '📁' : '📄' %> + <% if (item.contentType === 'directory') { %> + <%= item.name %> + <% } else { %> + <%= item.name %> + <% } %> +
-- cgit v1.3.1