-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switch publisher to Bootstrap based templates & add dark theme (#302)
Signed-off-by: Igor Shishkin <me@teran.ru>
- Loading branch information
Showing
21 changed files
with
595 additions
and
138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package html | ||
|
||
import "strconv" | ||
|
||
type Pagination struct { | ||
HasPrevious bool | ||
PreviousPageNum uint64 | ||
PreviousPageURL string | ||
Pages []Page | ||
HasNext bool | ||
NextPageNum uint64 | ||
NextPageURL string | ||
} | ||
|
||
type Page struct { | ||
IsCurrent bool | ||
Number uint64 | ||
URL string | ||
} | ||
|
||
func NewPagination(total, current, maxPages uint64, pageURL string) Pagination { | ||
pages := []Page{} | ||
max := current + maxPages | ||
if current+maxPages > total { | ||
max = total | ||
} | ||
for i := current; i <= max; i++ { | ||
isCurrent := false | ||
if i == current { | ||
isCurrent = true | ||
} | ||
pages = append(pages, Page{ | ||
IsCurrent: isCurrent, | ||
Number: i, | ||
URL: pageURL + "?page=" + strconv.FormatUint(i, 10), | ||
}) | ||
} | ||
|
||
var ( | ||
hasPrevious bool | ||
previousPageNum uint64 | ||
previousPageURL string | ||
) | ||
if current > 1 { | ||
hasPrevious = true | ||
previousPageNum = current - 1 | ||
previousPageURL = pageURL + "?page=" + strconv.FormatUint(previousPageNum, 10) | ||
} | ||
|
||
var ( | ||
hasNext bool | ||
nextPageNum uint64 | ||
nextPageURL string | ||
) | ||
if max < total { | ||
hasNext = true | ||
nextPageNum = current + maxPages + 1 | ||
nextPageURL = pageURL + "?page=" + strconv.FormatUint(nextPageNum, 10) | ||
} | ||
|
||
return Pagination{ | ||
HasPrevious: hasPrevious, | ||
PreviousPageNum: previousPageNum, | ||
PreviousPageURL: previousPageURL, | ||
Pages: pages, | ||
HasNext: hasNext, | ||
NextPageNum: nextPageNum, | ||
NextPageURL: nextPageURL, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package html | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestPagination(t *testing.T) { | ||
r := require.New(t) | ||
|
||
pagination := NewPagination(305, 10, 3, "/some/page") | ||
r.Equal(Pagination{ | ||
HasPrevious: true, | ||
PreviousPageNum: 9, | ||
PreviousPageURL: "/some/page?page=9", | ||
Pages: []Page{ | ||
{IsCurrent: true, URL: "/some/page?page=10", Number: 10}, | ||
{IsCurrent: false, URL: "/some/page?page=11", Number: 11}, | ||
{IsCurrent: false, URL: "/some/page?page=12", Number: 12}, | ||
{IsCurrent: false, URL: "/some/page?page=13", Number: 13}, | ||
}, | ||
HasNext: true, | ||
NextPageNum: 14, | ||
NextPageURL: "/some/page?page=14", | ||
}, pagination) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
window.addEventListener('load', () => { | ||
const currentSwitch = localStorage.getItem('lightSwitch')?.toString() | ||
const htmlTag = document.getElementById('html'); | ||
const lightSwitch = document.getElementById('lightSwitch'); | ||
|
||
if (currentSwitch) { | ||
htmlTag?.setAttribute('data-bs-theme', currentSwitch); | ||
} | ||
|
||
lightSwitch?.addEventListener('click', () => { | ||
if (document.getElementById('html')?.getAttribute('data-bs-theme')?.toString() == "dark") { | ||
htmlTag?.setAttribute('data-bs-theme', 'light'); | ||
lightSwitch?.classList.remove('dark'); | ||
lightSwitch?.classList.add('light'); | ||
|
||
localStorage.setItem('lightSwitch', 'light'); | ||
return | ||
} | ||
htmlTag?.setAttribute('data-bs-theme', 'dark'); | ||
lightSwitch?.classList.remove('light'); | ||
lightSwitch?.classList.add('dark'); | ||
|
||
localStorage.setItem('lightSwitch', 'dark'); | ||
return | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
.container { | ||
margin: 15px; | ||
} | ||
nav.pagination { | ||
margin-left: 45px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,21 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<title>Resource not found</title> | ||
</head> | ||
<body> | ||
|
||
<head> | ||
<title>Resource not found</title> | ||
</head> | ||
|
||
<body> | ||
<div class="container"> | ||
<h1>404 Not Found</h1> | ||
<p> | ||
There is not the resource you are looking for | ||
</p> | ||
<hr> | ||
</div> | ||
<hr> | ||
<div class="container"> | ||
Powered by <a href="https://github.com/teran/archived" target="_blank" rel="noopener">archived</a> | ||
</body> | ||
</div> | ||
</body> | ||
|
||
</html> |
Oops, something went wrong.