-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a24123b
commit bc921a5
Showing
34 changed files
with
4,360 additions
and
7 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
Large diffs are not rendered by default.
Oops, something went wrong.
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,62 @@ | ||
Copyright (c) 2024. All rights reserved. | ||
|
||
Project Owner: | ||
NewTendermint, LLC | ||
|
||
Project Maintainer: | ||
İlker Göktuğ ÖZTÜRK. <[email protected]>, <[email protected]> | ||
|
||
Your access to this Project and your contributions to this Project are subject | ||
to the following terms: | ||
|
||
* You hereby grant to the listed Owner and Maintainer of this Project the | ||
worldwide, irrevocable and royalty-free right to use, publish, relicense and | ||
sublicense your contributions under any non-exclusive license of their | ||
choosing for commercial and non-commercial purposes. | ||
* You shall not attempt to bring any intellectual property infringement or | ||
misappropriation claims against the Owner or Maintainer of this Project | ||
relating to or arising from your contributions. | ||
* You represent that you are the sole owner of all rights in your | ||
contributions and that no third party has any rights or interests therein. | ||
|
||
FOR THE SCOPE OF THIS LICENSE, A CONTRIBUTION IS DEFINED TO INCLUDE ANY WORKS, | ||
IDEAS, CODE, PROCESSES, OR APIS MADE AVAILABLE TO VIEW BY THE GENERAL PUBLIC | ||
(INCLUDING ANY PUBLICLY ACCESSIBLE INTERNET FORUMS AND CHAT SERVERS WHERE | ||
ACCESS IS AVAILABLE FOR FREE WITH REGISTRATION) OR PRIVATELY TO THIS PROJECT'S | ||
OWNER AND MAINTAINERS; INCLUDING WORKS, IDEAS, CODE, PROCESSES, AND APIS THAT | ||
ARE ABOUT THIS PROJECT AND ITS CONTRIBUTIONS, OR MENTIONED IN REFERENCE TO | ||
THIS PROJECT, WHERE SUCH WORKS, IDEAS, CODE, PROCESSES, AND APIS ARE MATERIAL | ||
TO THE SUCCESS, IMPROVEMENT, OR COMPLETION OF THIS PROJECT, AS DETERMINED BY | ||
THE OWNER OF THIS PROJECT. | ||
|
||
Contributions may come in any form, and include (but are not limited to): | ||
|
||
* pull requests | ||
* diff patches | ||
* commentary | ||
* example code | ||
|
||
If you do not want your contribution to become incorporated into this Project, | ||
do not make contributions to this Project. The creation of contributions that | ||
may in the future become known to this Project's Owner and Maintainer | ||
constitutes a willing contribution to this Project in accordance with this | ||
license. | ||
|
||
THIS PROJECT AND THE WORKS AVAILABLE THROUGH THIS PROJECT ARE PROVIDED “AS IS” | ||
AND WITHOUT WARRANTY OF ANY KIND. IN NO EVENT SHALL THE OWNER OR MAINTAINER OF | ||
THIS PROJECT BE LIABLE TO YOU OR ANY THIRD PARTY FOR ANY CLAIM, DAMAGES OR | ||
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
FROM, OUT OF OR IN CONNECTION WITH THIS PROJECT OR THE WORKS AVAILABLE THROUGH | ||
THIS PROJECT. YOU AGREED TO INDEMNIFY, DEFEND AND HOLD THE OWNER AND | ||
MAINTAINER FROM AND AGAINST ANY CLAIMS, LOSSES OR DAMAGES ARISING FROM YOUR | ||
USE OF THIS PROJECT OR THE WORKS AVAILABLE THROUGH THIS PROJECT. | ||
|
||
This license is subject to change at any time by the Project Owner or | ||
Maintainer. | ||
|
||
Your continued access to or use of this Project or any works | ||
available through this Project shall be subject to the then-current version | ||
of this license. | ||
|
||
The Project Owner and Maintainer reserve the right to change this license | ||
without needing the consent of the contributors to this Project. |
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,64 @@ | ||
package alerts | ||
|
||
import ( | ||
"gno.land/p/demo/ufmt" | ||
) | ||
|
||
const ( | ||
TypeError Type = "alerts-error" | ||
TypeWarning Type = "alerts-warning" | ||
) | ||
|
||
const ( | ||
StyleError = ` | ||
.alerts-error { | ||
padding: .75rem 1.25rem; | ||
border: 1px solid #f5c6cb; | ||
background-color: #f8d7da; | ||
color: #721c24; | ||
border-radius: .25rem; | ||
} | ||
` | ||
StyleWarning = ` | ||
.alerts-warning { | ||
padding: .75rem 1.25rem; | ||
border: 1px solid #ffeeba; | ||
background-color: #fff3cd; | ||
color: #856404; | ||
border-radius: .25rem; | ||
} | ||
` | ||
) | ||
|
||
// Type defines the type of alerts. | ||
type Type string | ||
|
||
// NewAlert returns HTML for an alert. | ||
func NewAlert(t Type, content string) string { | ||
var css string | ||
switch t { | ||
case TypeWarning: | ||
css = StyleWarning | ||
case TypeError: | ||
css = StyleError | ||
default: | ||
panic("unknown alert type") | ||
} | ||
|
||
return "\n\n" + ufmt.Sprintf(`<p class="%s">%s</p><style>%s</style>`, string(t), content, css) + "\n\n" | ||
} | ||
|
||
// NewWarning returns HTML for a warning alert. | ||
func NewWarning(content string) string { | ||
return NewAlert(TypeWarning, content) | ||
} | ||
|
||
// NewError returns HTML for an error alert. | ||
func NewError(content string) string { | ||
return NewAlert(TypeError, content) | ||
} | ||
|
||
// NewLink returns an HTML link. | ||
func NewLink(href, label string) string { | ||
return ufmt.Sprintf(`<a href="%s">%s</a>`, href, label) | ||
} |
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 @@ | ||
{"creator":"g147ah9520z0r6jh9mjr6c75rv6l8aypzvcd3f7d","deposit":"1ugnot"} |
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,62 @@ | ||
Copyright (c) 2024. All rights reserved. | ||
|
||
Project Owner: | ||
NewTendermint, LLC | ||
|
||
Project Maintainer: | ||
İlker Göktuğ ÖZTÜRK. <[email protected]>, <[email protected]> | ||
|
||
Your access to this Project and your contributions to this Project are subject | ||
to the following terms: | ||
|
||
* You hereby grant to the listed Owner and Maintainer of this Project the | ||
worldwide, irrevocable and royalty-free right to use, publish, relicense and | ||
sublicense your contributions under any non-exclusive license of their | ||
choosing for commercial and non-commercial purposes. | ||
* You shall not attempt to bring any intellectual property infringement or | ||
misappropriation claims against the Owner or Maintainer of this Project | ||
relating to or arising from your contributions. | ||
* You represent that you are the sole owner of all rights in your | ||
contributions and that no third party has any rights or interests therein. | ||
|
||
FOR THE SCOPE OF THIS LICENSE, A CONTRIBUTION IS DEFINED TO INCLUDE ANY WORKS, | ||
IDEAS, CODE, PROCESSES, OR APIS MADE AVAILABLE TO VIEW BY THE GENERAL PUBLIC | ||
(INCLUDING ANY PUBLICLY ACCESSIBLE INTERNET FORUMS AND CHAT SERVERS WHERE | ||
ACCESS IS AVAILABLE FOR FREE WITH REGISTRATION) OR PRIVATELY TO THIS PROJECT'S | ||
OWNER AND MAINTAINERS; INCLUDING WORKS, IDEAS, CODE, PROCESSES, AND APIS THAT | ||
ARE ABOUT THIS PROJECT AND ITS CONTRIBUTIONS, OR MENTIONED IN REFERENCE TO | ||
THIS PROJECT, WHERE SUCH WORKS, IDEAS, CODE, PROCESSES, AND APIS ARE MATERIAL | ||
TO THE SUCCESS, IMPROVEMENT, OR COMPLETION OF THIS PROJECT, AS DETERMINED BY | ||
THE OWNER OF THIS PROJECT. | ||
|
||
Contributions may come in any form, and include (but are not limited to): | ||
|
||
* pull requests | ||
* diff patches | ||
* commentary | ||
* example code | ||
|
||
If you do not want your contribution to become incorporated into this Project, | ||
do not make contributions to this Project. The creation of contributions that | ||
may in the future become known to this Project's Owner and Maintainer | ||
constitutes a willing contribution to this Project in accordance with this | ||
license. | ||
|
||
THIS PROJECT AND THE WORKS AVAILABLE THROUGH THIS PROJECT ARE PROVIDED “AS IS” | ||
AND WITHOUT WARRANTY OF ANY KIND. IN NO EVENT SHALL THE OWNER OR MAINTAINER OF | ||
THIS PROJECT BE LIABLE TO YOU OR ANY THIRD PARTY FOR ANY CLAIM, DAMAGES OR | ||
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
FROM, OUT OF OR IN CONNECTION WITH THIS PROJECT OR THE WORKS AVAILABLE THROUGH | ||
THIS PROJECT. YOU AGREED TO INDEMNIFY, DEFEND AND HOLD THE OWNER AND | ||
MAINTAINER FROM AND AGAINST ANY CLAIMS, LOSSES OR DAMAGES ARISING FROM YOUR | ||
USE OF THIS PROJECT OR THE WORKS AVAILABLE THROUGH THIS PROJECT. | ||
|
||
This license is subject to change at any time by the Project Owner or | ||
Maintainer. | ||
|
||
Your continued access to or use of this Project or any works | ||
available through this Project shall be subject to the then-current version | ||
of this license. | ||
|
||
The Project Owner and Maintainer reserve the right to change this license | ||
without needing the consent of the contributors to this Project. |
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,88 @@ | ||
package blog | ||
|
||
import ( | ||
"crypto/sha256" | ||
"encoding/hex" | ||
"net/url" | ||
"regexp" | ||
"strings" | ||
) | ||
|
||
var ( | ||
hostnameRe = regexp.MustCompile(`^(?i)[a-z0-9-]+(\.[a-z0-9-]+)+\.?$`) | ||
sha256Re = regexp.MustCompile(`^[a-f0-9]{64}$`) | ||
slugRe = regexp.MustCompile(`^[a-z0-9\p{L}]+(?:-[a-z0-9\p{L}]+)*$`) | ||
) | ||
|
||
// AssertIsSlug asserts that a URL slug is valid. | ||
func AssertIsSlug(slug string) { | ||
if !IsSlug(slug) { | ||
panic("URL slug is not valid") | ||
} | ||
} | ||
|
||
// AssertContentSha256Hash asserts that a hex hash is a valid SHA256 hash. | ||
func AssertIsSha256Hash(hexHash string) { | ||
if !IsSha256Hash(hexHash) { | ||
panic("invalid sha256 hash") | ||
} | ||
} | ||
|
||
// AssertIsContentURL asserts that a URL is a valid link to a content. | ||
// URL must have a path to ve valid. Website URLs will fail. | ||
func AssertIsContentURL(url string) { | ||
if !IsURL(url, true) { | ||
panic("content URL is not valid, make sure path to content is specified") | ||
} | ||
} | ||
|
||
// AssertTitleIsNotEmpty asserts that a title is not an empty string. | ||
func AssertTitleIsNotEmpty(title string) { | ||
if strings.TrimSpace(title) == "" { | ||
panic("title is empty") | ||
} | ||
} | ||
|
||
// AssertContentSha256Hash asserts that the SHA256 hash of a content matches a hash. | ||
func AssertContentSha256Hash(content, hash string) { | ||
if hash != GetHexSha256Hash(content) { | ||
panic("content sha256 checksum is not valid") | ||
} | ||
} | ||
|
||
// IsSlug checks if a string is a valid URL slug. | ||
func IsSlug(slug string) bool { | ||
return slugRe.MatchString(slug) | ||
} | ||
|
||
// IsSha256Hash checks is a hex hash is a valid SHA256 hash. | ||
func IsSha256Hash(hexHash string) bool { | ||
return sha256Re.MatchString(strings.ToLower(hexHash)) | ||
} | ||
|
||
// IsURL checks if a URL is valid. | ||
// URL path availability can optionally be enforced. | ||
func IsURL(rawURL string, requirePath bool) bool { | ||
u, err := url.ParseRequestURI(rawURL) | ||
if err != nil { | ||
return false | ||
} | ||
|
||
if requirePath && u.Path == "" || u.Path == "/" { | ||
return false | ||
} | ||
|
||
if u.Scheme != "https" && u.Scheme != "http" { | ||
return false | ||
} | ||
|
||
hostname := u.Hostname() | ||
return hostname != "" && hostnameRe.MatchString(hostname) | ||
} | ||
|
||
// GetHexSha256Hash returns the hexadecimal encoding of the string's SHA256 hash. | ||
// An empty string is returned when the argument is an empty string. | ||
func GetHexSha256Hash(s string) string { | ||
sum := sha256.Sum256([]byte(s)) | ||
return hex.EncodeToString(sum[:]) | ||
} |
Oops, something went wrong.