Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b5516d22e1 | ||
|
|
73b029dffa | ||
|
|
ab8ed5dd58 | ||
|
|
0da0bcaf01 | ||
|
|
3e1dcd609c | ||
|
|
251490523d | ||
|
|
789795d7fb | ||
|
|
482d2a0340 | ||
|
|
b0d08b0b2d | ||
|
|
4ea5f505e1 | ||
|
|
6594abfd76 | ||
|
|
8e58a42997 | ||
|
|
ed63d3d637 | ||
|
|
61c88f6532 | ||
|
|
05ae34b399 | ||
|
|
11821b1fe1 | ||
|
|
26a278eba8 | ||
|
|
3b7d4deeaa | ||
|
|
44e795b77d | ||
|
|
982e31c5be | ||
|
|
c643a95bda | ||
|
|
ba85819607 | ||
|
|
f276f4d64a | ||
|
|
375d22d230 | ||
|
|
bec10e41b5 | ||
|
|
a8daef8401 | ||
|
|
ee6bf8e8b7 | ||
|
|
bb86406b9d | ||
|
|
28cf6b3866 | ||
|
|
8b45bd4fcc | ||
|
|
5fb147fe78 | ||
|
|
fd1559928a | ||
|
|
95a3a717ed | ||
|
|
8dbd86535d | ||
|
|
f534cc9f9b | ||
|
|
a77cafb3ae | ||
|
|
48cbbf652a | ||
|
|
e05f572eb2 | ||
|
|
7ddb288ae3 | ||
|
|
cee889bd58 | ||
|
|
aacd7d3d0c | ||
|
|
3134869cce | ||
|
|
083de67f45 | ||
|
|
339af195c2 | ||
|
|
83e2689111 | ||
|
|
68a680d1b0 | ||
|
|
f54ee176fc | ||
|
|
45b1985b97 | ||
|
|
35ecbe8f09 | ||
|
|
46304124ec | ||
|
|
1f29da565f | ||
|
|
8dbb4ebdc5 | ||
|
|
c5dba02ee6 | ||
|
|
7b4bf5c1b2 | ||
|
|
78107a0269 | ||
|
|
528e59e922 | ||
|
|
ad1a4272b0 | ||
|
|
9884cdaa8a | ||
|
|
cee61547fa | ||
|
|
ce8cb5ee19 | ||
|
|
5631982c2b | ||
|
|
4cb17a6518 | ||
|
|
05f387ffa1 | ||
|
|
265880c2cf | ||
|
|
316410bd35 | ||
|
|
3d47537e1f | ||
|
|
567e0c6ef0 | ||
|
|
73bffef9af | ||
|
|
e5a5d63c6f | ||
|
|
6c98a50085 |
@@ -1,8 +1,8 @@
|
||||
Write.as web core
|
||||
=================
|
||||
WriteFreely web core
|
||||
====================
|
||||
[](https://godoc.org/github.com/writeas/web-core)
|
||||
[](https://travis-ci.org/writeas/web-core)
|
||||
[](http://slack.write.as/)
|
||||
[](http://webchat.freenode.net/?channels=writefreely)
|
||||
[](https://discuss.write.as/c/development)
|
||||
|
||||
web-core holds components of the [Write.as](https://write.as) web application.
|
||||
web-core holds components of the [WriteFreely](https://writefreely.org) web application, and is shared with other [Write.as](https://write.as) products, like [Snap.as](https://snap.as).
|
||||
|
||||
+2
-2
@@ -69,8 +69,8 @@ func parsePublicKey(der []byte) (crypto.PublicKey, error) {
|
||||
// them in that order.
|
||||
func DecodePrivateKey(k []byte) (crypto.PrivateKey, error) {
|
||||
block, _ := pem.Decode(k)
|
||||
if block == nil || block.Type != "RSA PRIVATE KEY" {
|
||||
return nil, fmt.Errorf("failed to decode PEM block containing private key")
|
||||
if block == nil || (block.Type != "RSA PRIVATE KEY" && block.Type != "PRIVATE KEY") {
|
||||
return nil, fmt.Errorf("failed to decode PEM block containing private key, type %s", block.Type)
|
||||
}
|
||||
|
||||
return parsePrivateKey(block.Bytes)
|
||||
|
||||
@@ -11,6 +11,8 @@ const (
|
||||
toPublic = "https://www.w3.org/ns/activitystreams#Public"
|
||||
)
|
||||
|
||||
var Extensions = map[string]string{}
|
||||
|
||||
// Activity describes actions that have either already occurred, are in the
|
||||
// process of occurring, or may occur in the future.
|
||||
type Activity struct {
|
||||
@@ -38,6 +40,7 @@ func NewCreateActivity(o *Object) *Activity {
|
||||
BaseObject: BaseObject{
|
||||
Context: []interface{}{
|
||||
Namespace,
|
||||
Extensions,
|
||||
},
|
||||
ID: o.ID,
|
||||
Type: "Create",
|
||||
@@ -56,6 +59,7 @@ func NewUpdateActivity(o *Object) *Activity {
|
||||
BaseObject: BaseObject{
|
||||
Context: []interface{}{
|
||||
Namespace,
|
||||
Extensions,
|
||||
},
|
||||
ID: o.ID,
|
||||
Type: "Update",
|
||||
@@ -102,17 +106,31 @@ func NewFollowActivity(actorIRI, followeeIRI string) *FollowActivity {
|
||||
// Object is the primary base type for the Activity Streams vocabulary.
|
||||
type Object struct {
|
||||
BaseObject
|
||||
Published time.Time `json:"published"`
|
||||
Published time.Time `json:"published,omitempty"`
|
||||
Summary *string `json:"summary,omitempty"`
|
||||
InReplyTo *string `json:"inReplyTo"`
|
||||
InReplyTo *string `json:"inReplyTo,omitempty"`
|
||||
URL string `json:"url"`
|
||||
AttributedTo string `json:"attributedTo"`
|
||||
To []string `json:"to"`
|
||||
AttributedTo string `json:"attributedTo,omitempty"`
|
||||
To []string `json:"to,omitempty"`
|
||||
CC []string `json:"cc,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
Content string `json:"content"`
|
||||
Content string `json:"content,omitempty"`
|
||||
ContentMap map[string]string `json:"contentMap,omitempty"`
|
||||
Tag []Tag `json:"tag"`
|
||||
Tag []Tag `json:"tag,omitempty"`
|
||||
Attachment []Attachment `json:"attachment,omitempty"`
|
||||
|
||||
// Person
|
||||
Inbox string `json:"inbox,omitempty"`
|
||||
Outbox string `json:"outbox,omitempty"`
|
||||
Following string `json:"following,omitempty"`
|
||||
Followers string `json:"followers,omitempty"`
|
||||
PreferredUsername string `json:"preferredUsername,omitempty"`
|
||||
Icon *Image `json:"icon,omitempty"`
|
||||
PublicKey *PublicKey `json:"publicKey,omitempty"`
|
||||
Endpoints *Endpoints `json:"endpoints,omitempty"`
|
||||
|
||||
// Extensions
|
||||
// NOTE: add extensions here
|
||||
}
|
||||
|
||||
// NewNoteObject creates a basic Note object that includes the public
|
||||
@@ -142,3 +160,13 @@ func NewArticleObject() *Object {
|
||||
}
|
||||
return &o
|
||||
}
|
||||
|
||||
// NewPersonObject creates a basic Person object.
|
||||
func NewPersonObject() *Object {
|
||||
o := Object{
|
||||
BaseObject: BaseObject{
|
||||
Type: "Person",
|
||||
},
|
||||
}
|
||||
return &o
|
||||
}
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
package activitystreams
|
||||
|
||||
import (
|
||||
"mime"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type Attachment struct {
|
||||
Type AttachmentType `json:"type"`
|
||||
URL string `json:"url"`
|
||||
MediaType string `json:"mediaType"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
type AttachmentType string
|
||||
|
||||
const (
|
||||
AttachImage AttachmentType = "Image"
|
||||
AttachDocument AttachmentType = "Document"
|
||||
)
|
||||
|
||||
// NewImageAttachment creates a new Attachment from the given URL, setting the
|
||||
// correct type and automatically detecting the MediaType based on the file
|
||||
// extension.
|
||||
func NewImageAttachment(url string) Attachment {
|
||||
return newAttachment(url, AttachImage)
|
||||
}
|
||||
|
||||
// NewDocumentAttachment creates a new Attachment from the given URL, setting the
|
||||
// correct type and automatically detecting the MediaType based on the file
|
||||
// extension.
|
||||
func NewDocumentAttachment(url string) Attachment {
|
||||
return newAttachment(url, AttachDocument)
|
||||
}
|
||||
|
||||
func newAttachment(url string, attachType AttachmentType) Attachment {
|
||||
var fileType string
|
||||
extIdx := strings.LastIndexByte(url, '.')
|
||||
if extIdx > -1 {
|
||||
fileType = mime.TypeByExtension(url[extIdx:])
|
||||
}
|
||||
return Attachment{
|
||||
Type: attachType,
|
||||
URL: url,
|
||||
MediaType: fileType,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package activitystreams
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestNewImageAttachment(t *testing.T) {
|
||||
type args struct {
|
||||
url string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want Attachment
|
||||
}{
|
||||
{name: "good svg", args: args{"https://writefreely.org/img/writefreely.svg"}, want: Attachment{
|
||||
Type: "Image",
|
||||
URL: "https://writefreely.org/img/writefreely.svg",
|
||||
MediaType: "image/svg+xml",
|
||||
}},
|
||||
{name: "good png", args: args{"https://i.snap.as/12345678.png"}, want: Attachment{
|
||||
Type: "Image",
|
||||
URL: "https://i.snap.as/12345678.png",
|
||||
MediaType: "image/png",
|
||||
}},
|
||||
{name: "no extension", args: args{"https://i.snap.as/12345678"}, want: Attachment{
|
||||
Type: "Image",
|
||||
URL: "https://i.snap.as/12345678",
|
||||
MediaType: "",
|
||||
}},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := NewImageAttachment(tt.args.url); !reflect.DeepEqual(got, tt.want) {
|
||||
t.Errorf("NewImageAttachment() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestNewDocumentAttachment(t *testing.T) {
|
||||
type args struct {
|
||||
url string
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want Attachment
|
||||
}{
|
||||
{name: "mp3", args: args{"https://listen.as/matt/abc.mp3"}, want: Attachment{
|
||||
Type: "Document",
|
||||
URL: "https://listen.as/matt/abc.mp3",
|
||||
MediaType: "audio/mpeg",
|
||||
}},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := NewDocumentAttachment(tt.args.url); !reflect.DeepEqual(got, tt.want) {
|
||||
t.Errorf("NewDocumentAttachment() = %+v, want %+v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,7 @@ type (
|
||||
}
|
||||
|
||||
Endpoints struct {
|
||||
SharedInbox string `json:"sharedInbox"`
|
||||
SharedInbox string `json:"sharedInbox,omitempty"`
|
||||
}
|
||||
|
||||
Image struct {
|
||||
|
||||
@@ -10,5 +10,5 @@ type TagType string
|
||||
|
||||
const (
|
||||
TagHashtag TagType = "Hashtag"
|
||||
TagMention = "Mention"
|
||||
TagMention TagType = "Mention"
|
||||
)
|
||||
|
||||
+3
-3
@@ -1,7 +1,7 @@
|
||||
package auth
|
||||
|
||||
import (
|
||||
uuid "github.com/nu7hatch/gouuid"
|
||||
uuid "github.com/gofrs/uuid"
|
||||
"github.com/writeas/web-core/log"
|
||||
"strings"
|
||||
)
|
||||
@@ -16,7 +16,7 @@ func GetToken(header string) []byte {
|
||||
token = f[1]
|
||||
}
|
||||
}
|
||||
t, err := uuid.ParseHex(token)
|
||||
t, err := uuid.FromString(token)
|
||||
if err != nil {
|
||||
log.Error("Couldn't parseHex on '%s': %v", accessToken, err)
|
||||
} else {
|
||||
@@ -31,7 +31,7 @@ func GetHeaderToken(header string) []byte {
|
||||
if len(header) > 0 {
|
||||
f := strings.Fields(header)
|
||||
if len(f) == 2 && f[0] == "Token" {
|
||||
t, err := uuid.ParseHex(f[1])
|
||||
t, err := uuid.FromString(f[1])
|
||||
if err != nil {
|
||||
log.Error("Couldn't parseHex on '%s': %v", accessToken, err)
|
||||
} else {
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
// Package category supports post categories
|
||||
package category
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"github.com/writeas/slug"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrNotFound = errors.New("category doesn't exist")
|
||||
)
|
||||
|
||||
// Category represents a post tag with additional metadata, like a title and slug.
|
||||
type Category struct {
|
||||
ID int64 `json:"-"`
|
||||
Hashtag string `json:"hashtag"`
|
||||
Slug string `json:"slug"`
|
||||
Title string `json:"title"`
|
||||
PostCount int64 `json:"post_count"`
|
||||
}
|
||||
|
||||
// NewCategory creates a Category you can insert into the database, based on a hashtag. It automatically breaks up the
|
||||
// hashtag by words, based on capitalization, for both the title and a URL-friendly slug.
|
||||
func NewCategory(hashtag string) *Category {
|
||||
title := titleFromHashtag(hashtag)
|
||||
return &Category{
|
||||
Hashtag: hashtag,
|
||||
Slug: slug.Make(title),
|
||||
Title: title,
|
||||
}
|
||||
}
|
||||
|
||||
// NewCategoryFromPartial creates a Category from a partially-populated Category, such as when a user initially creates
|
||||
// one.
|
||||
func NewCategoryFromPartial(cat *Category) *Category {
|
||||
newCat := &Category{
|
||||
Hashtag: cat.Hashtag,
|
||||
}
|
||||
// Create title from hashtag, if none supplied
|
||||
if cat.Title == "" {
|
||||
newCat.Title = titleFromHashtag(cat.Hashtag)
|
||||
} else {
|
||||
newCat.Title = cat.Title
|
||||
}
|
||||
// Create slug from title, if none supplied; otherwise ensure slug is valid
|
||||
if cat.Slug == "" {
|
||||
newCat.Slug = slug.Make(newCat.Title)
|
||||
} else {
|
||||
newCat.Slug = slug.Make(cat.Slug)
|
||||
}
|
||||
return newCat
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package category
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"unicode"
|
||||
)
|
||||
|
||||
// titleFromHashtag generates an all-lowercase title, with spaces inserted based on initial capitalization -- e.g.
|
||||
// "MyWordyTag" becomes "my wordy tag".
|
||||
func titleFromHashtag(hashtag string) string {
|
||||
var t strings.Builder
|
||||
var prev rune
|
||||
for i, c := range hashtag {
|
||||
if unicode.IsUpper(c) {
|
||||
if i > 0 && !unicode.IsUpper(prev) {
|
||||
// Insert space if previous rune wasn't also uppercase (e.g. an abbreviation)
|
||||
t.WriteRune(' ')
|
||||
}
|
||||
t.WriteRune(unicode.ToLower(c))
|
||||
} else {
|
||||
t.WriteRune(c)
|
||||
}
|
||||
prev = c
|
||||
}
|
||||
return t.String()
|
||||
}
|
||||
|
||||
// HashtagFromTitle generates a valid single-word, camelCase hashtag from a title (which might include spaces,
|
||||
// punctuation, etc.).
|
||||
func HashtagFromTitle(title string) string {
|
||||
var t strings.Builder
|
||||
var prev rune
|
||||
for _, c := range title {
|
||||
if !unicode.IsLetter(c) && !unicode.IsNumber(c) {
|
||||
prev = c
|
||||
continue
|
||||
}
|
||||
if unicode.IsSpace(prev) {
|
||||
// Uppercase next word
|
||||
t.WriteRune(unicode.ToUpper(c))
|
||||
} else {
|
||||
t.WriteRune(c)
|
||||
}
|
||||
prev = c
|
||||
}
|
||||
return t.String()
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
package category
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestTitleFromHashtag(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
hashtag string
|
||||
expTitle string
|
||||
}{
|
||||
{"proper noun", "Jane", "jane"},
|
||||
{"full name", "JaneDoe", "jane doe"},
|
||||
{"us words", "unitedStates", "united states"},
|
||||
{"usa", "USA", "usa"},
|
||||
{"us monoword", "unitedstates", "unitedstates"},
|
||||
{"100dto", "100DaysToOffload", "100 days to offload"},
|
||||
{"iphone", "iPhone", "iphone"},
|
||||
{"ilike", "iLikeThis", "i like this"},
|
||||
{"abird", "aBird", "a bird"},
|
||||
{"all caps", "URGENT", "urgent"},
|
||||
{"smartphone", "スマートフォン", "スマートフォン"},
|
||||
}
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
res := titleFromHashtag(test.hashtag)
|
||||
if res != test.expTitle {
|
||||
t.Fatalf("#%s: got '%s' expected '%s'", test.hashtag, res, test.expTitle)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestHashtagFromTitle(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
title string
|
||||
expHashtag string
|
||||
}{
|
||||
{"proper noun", "Jane", "Jane"},
|
||||
{"full name", "Jane Doe", "JaneDoe"},
|
||||
{"us upper words", "United States", "UnitedStates"},
|
||||
{"us lower words", "united states", "unitedStates"},
|
||||
{"usa", "USA", "USA"},
|
||||
{"100dto", "100 Days To Offload", "100DaysToOffload"},
|
||||
{"iphone", "iPhone", "iPhone"},
|
||||
{"ilike", "I like this", "ILikeThis"},
|
||||
{"abird", "a Bird", "aBird"},
|
||||
{"all caps", "URGENT", "URGENT"},
|
||||
{"punctuation", "John’s Stories", "JohnsStories"},
|
||||
{"smartphone", "スマートフォン", "スマートフォン"},
|
||||
}
|
||||
for _, test := range tests {
|
||||
t.Run(test.name, func(t *testing.T) {
|
||||
res := HashtagFromTitle(test.title)
|
||||
if res != test.expHashtag {
|
||||
t.Fatalf("%s: got '%s' expected '%s'", test.title, res, test.expHashtag)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -80,3 +80,24 @@ func (v *NullJSONString) UnmarshalJSON(data []byte) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func ConvertJSONNullString(value string) reflect.Value {
|
||||
v := NullJSONString{}
|
||||
if err := v.Scan(value); err != nil {
|
||||
return reflect.Value{}
|
||||
}
|
||||
|
||||
return reflect.ValueOf(v)
|
||||
}
|
||||
|
||||
func ConvertJSONNullBool(value string) reflect.Value {
|
||||
v := NullJSONBool{}
|
||||
|
||||
if value == "on" || value == "off" {
|
||||
return reflect.ValueOf(NullJSONBool{sql.NullBool{Bool: value == "on", Valid: true}})
|
||||
}
|
||||
if err := v.Scan(value); err != nil {
|
||||
return reflect.Value{}
|
||||
}
|
||||
return reflect.ValueOf(v)
|
||||
}
|
||||
|
||||
@@ -40,3 +40,39 @@ func SQLNullFloat64(value string) reflect.Value {
|
||||
|
||||
return reflect.ValueOf(v)
|
||||
}
|
||||
|
||||
func ConvertSQLNullString(value string) reflect.Value {
|
||||
v := sql.NullString{}
|
||||
if err := v.Scan(value); err != nil {
|
||||
return reflect.Value{}
|
||||
}
|
||||
|
||||
return reflect.ValueOf(v)
|
||||
}
|
||||
|
||||
func ConvertSQLNullBool(value string) reflect.Value {
|
||||
v := sql.NullBool{}
|
||||
if err := v.Scan(value); err != nil {
|
||||
return reflect.Value{}
|
||||
}
|
||||
|
||||
return reflect.ValueOf(v)
|
||||
}
|
||||
|
||||
func ConvertSQLNullInt64(value string) reflect.Value {
|
||||
v := sql.NullInt64{}
|
||||
if err := v.Scan(value); err != nil {
|
||||
return reflect.Value{}
|
||||
}
|
||||
|
||||
return reflect.ValueOf(v)
|
||||
}
|
||||
|
||||
func ConvertSQLNullFloat64(value string) reflect.Value {
|
||||
v := sql.NullFloat64{}
|
||||
if err := v.Scan(value); err != nil {
|
||||
return reflect.Value{}
|
||||
}
|
||||
|
||||
return reflect.ValueOf(v)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
module github.com/writeas/web-core
|
||||
|
||||
go 1.10
|
||||
|
||||
require (
|
||||
github.com/gofrs/uuid v3.3.0+incompatible
|
||||
github.com/kylemcc/twitter-text-go v0.0.0-20180726194232-7f582f6736ec
|
||||
github.com/microcosm-cc/bluemonday v1.0.5
|
||||
github.com/rainycape/unidecode v0.0.0-20150907023854-cb7f23ec59be // indirect
|
||||
github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect
|
||||
github.com/writeas/go-strip-markdown v2.0.1+incompatible
|
||||
github.com/writeas/impart v1.1.1
|
||||
github.com/writeas/openssl-go v1.0.0
|
||||
github.com/writeas/saturday v1.7.1
|
||||
github.com/writeas/slug v1.2.0
|
||||
golang.org/x/crypto v0.0.0-20200109152110-61a87790db17
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
|
||||
gopkg.in/yaml.v1 v1.0.0-20140924161607-9f9df34309c0 // indirect
|
||||
)
|
||||
@@ -0,0 +1,44 @@
|
||||
github.com/aymerick/douceur v0.2.0 h1:Mv+mAeH1Q+n9Fr+oyamOlAkUNPWPlA8PPGR0QAaYuPk=
|
||||
github.com/aymerick/douceur v0.2.0/go.mod h1:wlT5vV2O3h55X9m7iVYN0TBM0NH/MmbLnd30/FjWUq4=
|
||||
github.com/chris-ramon/douceur v0.2.0 h1:IDMEdxlEUUBYBKE4z/mJnFyVXox+MjuEVDJNN27glkU=
|
||||
github.com/chris-ramon/douceur v0.2.0/go.mod h1:wDW5xjJdeoMm1mRt4sD4c/LbF/mWdEpRXQKjTR8nIBE=
|
||||
github.com/gofrs/uuid v3.3.0+incompatible h1:8K4tyRfvU1CYPgJsveYFQMhpFd/wXNM7iK6rR7UHz84=
|
||||
github.com/gofrs/uuid v3.3.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM=
|
||||
github.com/gorilla/css v1.0.0 h1:BQqNyPTi50JCFMTw/b67hByjMVXZRwGha6wxVGkeihY=
|
||||
github.com/gorilla/css v1.0.0/go.mod h1:Dn721qIggHpt4+EFCcTLTU/vk5ySda2ReITrtgBl60c=
|
||||
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
|
||||
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
|
||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
|
||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||
github.com/kylemcc/twitter-text-go v0.0.0-20180726194232-7f582f6736ec h1:ZXWuspqypleMuJy4bzYEqlMhJnGAYpLrWe5p7W3CdvI=
|
||||
github.com/kylemcc/twitter-text-go v0.0.0-20180726194232-7f582f6736ec/go.mod h1:voECJzdraJmolzPBgL9Z7ANwXf4oMXaTCsIkdiPpR/g=
|
||||
github.com/microcosm-cc/bluemonday v1.0.5 h1:cF59UCKMmmUgqN1baLvqU/B1ZsMori+duLVTLpgiG3w=
|
||||
github.com/microcosm-cc/bluemonday v1.0.5/go.mod h1:8iwZnFn2CDDNZ0r6UXhF4xawGvzaqzCRa1n3/lO3W2w=
|
||||
github.com/rainycape/unidecode v0.0.0-20150907023854-cb7f23ec59be h1:ta7tUOvsPHVHGom5hKW5VXNc2xZIkfCKP8iaqOyYtUQ=
|
||||
github.com/rainycape/unidecode v0.0.0-20150907023854-cb7f23ec59be/go.mod h1:MIDFMn7db1kT65GmV94GzpX9Qdi7N/pQlwb+AN8wh+Q=
|
||||
github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo=
|
||||
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
|
||||
github.com/writeas/go-strip-markdown v2.0.1+incompatible h1:IIqxTM5Jr7RzhigcL6FkrCNfXkvbR+Nbu1ls48pXYcw=
|
||||
github.com/writeas/go-strip-markdown v2.0.1+incompatible/go.mod h1:Rsyu10ZhbEK9pXdk8V6MVnZmTzRG0alMNLMwa0J01fE=
|
||||
github.com/writeas/impart v1.1.1 h1:RyA9+CqbdbDuz53k+nXCWUY+NlEkdyw6+nWanxSBl5o=
|
||||
github.com/writeas/impart v1.1.1/go.mod h1:g0MpxdnTOHHrl+Ca/2oMXUHJ0PcRAEWtkCzYCJUXC9Y=
|
||||
github.com/writeas/openssl-go v1.0.0 h1:YXM1tDXeYOlTyJjoMlYLQH1xOloUimSR1WMF8kjFc5o=
|
||||
github.com/writeas/openssl-go v1.0.0/go.mod h1:WsKeK5jYl0B5y8ggOmtVjbmb+3rEGqSD25TppjJnETA=
|
||||
github.com/writeas/saturday v1.7.1 h1:lYo1EH6CYyrFObQoA9RNWHVlpZA5iYL5Opxo7PYAnZE=
|
||||
github.com/writeas/saturday v1.7.1/go.mod h1:ETE1EK6ogxptJpAgUbcJD0prAtX48bSloie80+tvnzQ=
|
||||
github.com/writeas/slug v1.2.0 h1:EMQ+cwLiOcA6EtFwUgyw3Ge18x9uflUnOnR6bp/J+/g=
|
||||
github.com/writeas/slug v1.2.0/go.mod h1:RE8shOqQP3YhsfsQe0L3RnuejfQ4Mk+JjY5YJQFubfQ=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20200109152110-61a87790db17 h1:nVJ3guKA9qdkEQ3TUdXI9QSINo2CUPM/cySEvw2w8I0=
|
||||
golang.org/x/crypto v0.0.0-20200109152110-61a87790db17/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/net v0.0.0-20181220203305-927f97764cc3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3 h1:0GoQqolDA55aaLxZyTzK/Y2ePZzZTUrRacwib7cNsYQ=
|
||||
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
|
||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
|
||||
gopkg.in/yaml.v1 v1.0.0-20140924161607-9f9df34309c0 h1:POO/ycCATvegFmVuPpQzZFJ+pGZeX22Ufu6fibxDVjU=
|
||||
gopkg.in/yaml.v1 v1.0.0-20140924161607-9f9df34309c0/go.mod h1:WDnlLJ4WF5VGsH/HVa3CI79GS0ol3YnhVnKP89i0kNg=
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
package i18n
|
||||
|
||||
var rtlLangs = map[string]bool{
|
||||
"ar": true, // Arabic
|
||||
"dv": true, // Divehi
|
||||
"fa": true, // Persian (Farsi)
|
||||
"ha": true, // Hausa
|
||||
"he": true, // Hebrew
|
||||
"iw": true, // Hebrew (old code)
|
||||
"ji": true, // Yiddish (old code)
|
||||
"ps": true, // Pashto, Pushto
|
||||
"ur": true, // Urdu
|
||||
"yi": true, // Yiddish
|
||||
}
|
||||
|
||||
func LangIsRTL(lang string) bool {
|
||||
if _, ok := rtlLangs[lang]; ok {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package id
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// GenerateRandomString creates a random string of characters of the given
|
||||
// length from the given dictionary of possible characters.
|
||||
//
|
||||
// This example generates a hexadecimal string 6 characters long:
|
||||
// GenerateRandomString("0123456789abcdef", 6)
|
||||
func GenerateRandomString(dictionary string, l int) string {
|
||||
var bytes = make([]byte, l)
|
||||
rand.Read(bytes)
|
||||
for k, v := range bytes {
|
||||
bytes[k] = dictionary[v%byte(len(dictionary))]
|
||||
}
|
||||
return string(bytes)
|
||||
}
|
||||
|
||||
// GenSafeUniqueSlug generatees a reasonably unique random slug from the given
|
||||
// original slug. It's "safe" because it uses 0-9 b-z excluding vowels.
|
||||
func GenSafeUniqueSlug(slug string) string {
|
||||
return fmt.Sprintf("%s-%s", slug, GenerateRandomString("0123456789bcdfghjklmnpqrstvwxyz", 4))
|
||||
}
|
||||
|
||||
// Generate62RandomString creates a random string with the given length
|
||||
// consisting of characters in [A-Za-z0-9].
|
||||
func Generate62RandomString(l int) string {
|
||||
return GenerateRandomString("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", l)
|
||||
}
|
||||
|
||||
// GenerateFriendlyRandomString creates a random string of characters with the
|
||||
// given length consisting of characters in [a-z0-9].
|
||||
func GenerateFriendlyRandomString(l int) string {
|
||||
return GenerateRandomString("0123456789abcdefghijklmnopqrstuvwxyz", l)
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package id
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestGenSafeUniqueSlug(t *testing.T) {
|
||||
slug := "slug"
|
||||
r := map[string]bool{}
|
||||
|
||||
for i := 0; i < 1000; i++ {
|
||||
s := GenSafeUniqueSlug(slug)
|
||||
if s == slug {
|
||||
t.Errorf("Got same slug as inputted!")
|
||||
}
|
||||
if _, ok := r[s]; ok {
|
||||
t.Logf("#%d: slug %s was already generated in testing.", i, s)
|
||||
}
|
||||
r[s] = true
|
||||
}
|
||||
}
|
||||
@@ -14,16 +14,22 @@ var phrases = map[string]string{
|
||||
"Blogs": "Blogs",
|
||||
"Enter": "Enter",
|
||||
"Newer": "Newer",
|
||||
"Next": "Next",
|
||||
"Older": "Older",
|
||||
"Posts": "Posts",
|
||||
"Previous": "Previous",
|
||||
"Publish to...": "Publish to...",
|
||||
"Publish": "Publish",
|
||||
"Read more...": "Read more...",
|
||||
"Subscribe": "Subscribe",
|
||||
"This blog requires a password.": "This blog requires a password.",
|
||||
"Toggle theme": "Toggle theme",
|
||||
"View posts": "View Posts",
|
||||
"delete": "delete",
|
||||
"edit": "edit",
|
||||
"email subscription confirm": "Please check your email and click the confirmation link to subscribe.",
|
||||
"email subscription prompt": "Enter your email to subscribe to updates.",
|
||||
"email subscription success": "Subscribed. You'll now receive future blog posts via email.",
|
||||
"move to...": "move to...",
|
||||
"pin": "pin",
|
||||
"published with write.as": "published with write.as",
|
||||
@@ -32,4 +38,5 @@ var phrases = map[string]string{
|
||||
"share modal title": "Share this post",
|
||||
"share": "share",
|
||||
"unpin": "unpin",
|
||||
"title dash": "—",
|
||||
}
|
||||
|
||||
@@ -10,11 +10,13 @@ var phrasesAR = map[string]string{
|
||||
"Publish to...": "النشر إلى…",
|
||||
"Publish": "نشر",
|
||||
"Read more...": "اقرأ المزيد…",
|
||||
"Subscribe": "اشترك",
|
||||
"This blog requires a password.": "هذه المدونة تتطلب کلمة سرية.",
|
||||
"Toggle theme": "تغيير القالب",
|
||||
"View posts": "مشاهدة المنشورات",
|
||||
"delete": "حذف",
|
||||
"edit": "تعديل",
|
||||
"email subscription prompt": "ادخل عنوان بريدك الإلكتروني للإشتراك في التحديثات",
|
||||
"move to...": "أنقله إلى…",
|
||||
"pin": "تدبيس",
|
||||
"published with write.as": "مدعوم من write.as",
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package l10n
|
||||
|
||||
var phrasesCS = map[string]string{
|
||||
"Anonymous post": "Anonymní článek",
|
||||
"Blogs": "Blogy",
|
||||
"Enter": "Vstoupit",
|
||||
"Newer": "Novější",
|
||||
"Older": "Starší",
|
||||
"Posts": "Články",
|
||||
"Publish to...": "Zveřejnit do...",
|
||||
"Publish": "Zveřejnit",
|
||||
"Read more...": "Číst dále...",
|
||||
"Subscribe": "Odebírat",
|
||||
"This blog requires a password.": "Tento blog je zaheslován.",
|
||||
"Toggle theme": "Přepnout vzhled",
|
||||
"View posts": "Zobrazit články",
|
||||
"delete": "smazat",
|
||||
"edit": "upravit",
|
||||
"email subscription prompt": "Zadejte svůj e-mail a přihlaste se k odběru aktualizací.",
|
||||
"move to...": "přesunout do...",
|
||||
"pin": "připnout",
|
||||
"published with write.as": "publikováno pomocí write.as",
|
||||
"share modal ending": "Pošlete ji kamarádům, sdílejte na webu nebo na sociálních sítích. Zjistit více.",
|
||||
"share modal introduction": "Každý zveřejněný článek má tajnou unikátní adresu, kterou můžete komukoliv poslat. Unikátní adresa pro tento článek je:",
|
||||
"share modal title": "Sdílet tento článek",
|
||||
"share": "sdílet",
|
||||
"unpin": "odepnout",
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package l10n
|
||||
|
||||
var phrasesDA = map[string]string{
|
||||
"Anonymous post": "Anonymt indlæg",
|
||||
"Blogs": "Blogs",
|
||||
"Enter": "Enter",
|
||||
"Newer": "Nyere",
|
||||
"Older": "Ældre",
|
||||
"Posts": "Indlæg",
|
||||
"Publish to...": "Udgiv på...",
|
||||
"Publish": "Udgiv",
|
||||
"Read more...": "Læs videre...",
|
||||
"Subscribe": "Abonnér",
|
||||
"This blog requires a password.": "Den her blog kræver en adgangskode.",
|
||||
"Toggle theme": "Skift design",
|
||||
"View posts": "Vis indlæg",
|
||||
"delete": "slet",
|
||||
"edit": "redigér",
|
||||
"email subscription prompt": "Indtast din email for at få tilsendt opdateringer.",
|
||||
"move to...": "flyt til...",
|
||||
"pin": "sæt øverst",
|
||||
"published with write.as": "udgivet med write.as",
|
||||
"share modal ending": "Send det til en ven, del det på nettet, eller lav et tweet. Læs mere.",
|
||||
"share modal introduction": "Hvert indlæg har sit eget, hemmelige link, som du kan dele med enhver. Her er det førnævnte link:",
|
||||
"share modal title": "Del indlæg",
|
||||
"share": "del",
|
||||
"unpin": "fjern øverst",
|
||||
}
|
||||
+5
-2
@@ -7,20 +7,23 @@ var phrasesDE = map[string]string{
|
||||
"Newer": "Neuer",
|
||||
"Older": "Älter",
|
||||
"Posts": "Beiträge",
|
||||
"Publish to...": "Veröffentlichen zu...",
|
||||
"Publish to...": "Veröffentlichen zu",
|
||||
"Publish": "Veröffentlichen",
|
||||
"Read more...": "Weiterlesen...",
|
||||
"Subscribe": "Abonnieren",
|
||||
"This blog requires a password.": "Dieser Blog benötigt ein Passwort",
|
||||
"Toggle theme": "Design ändern",
|
||||
"View posts": "Beiträge ansehen",
|
||||
"delete": "Löschen",
|
||||
"edit": "Bearbeiten",
|
||||
"email subscription prompt": "Geben Sie Ihre E-Mail-Adresse ein, um Updates zu abonnieren.",
|
||||
"move to...": "Verschieben nach...",
|
||||
"pin": "Anheften",
|
||||
"published with write.as": "veröffentlicht mit write.as",
|
||||
"published with write.as": "Veröffentlicht mit write.as",
|
||||
"share modal ending": "Schicke es Freunden, teile es im Netz oder vielleicht tweete es. Lerne mehr.",
|
||||
"share modal introduction": "Jeder veröffentlichte Beitrag hat eine geheime, einmalige URL, die du mit jedem teilen kannst. Die URL ist:",
|
||||
"share modal title": "Teile diesen Beitrag",
|
||||
"share": "Teilen",
|
||||
"unpin": "Lösen",
|
||||
"title dash": "–",
|
||||
}
|
||||
|
||||
@@ -10,11 +10,13 @@ var phrasesEL = map[string]string{
|
||||
"Publish to...": "Δημοσίευση στο...",
|
||||
"Publish": "Δημοσίευση",
|
||||
"Read more...": "Διαβάστε περισσότερα...",
|
||||
"Subscribe": "Εγγραφείτε",
|
||||
"This blog requires a password.": "Αυτό το ιστολόγιο απαιτεί κωδικό.",
|
||||
"Toggle theme": "Αλλαγή θέματος",
|
||||
"View posts": "Προβολή Δημοσιεύσεων",
|
||||
"delete": "διαγραφή",
|
||||
"edit": "επεξεργασία",
|
||||
"email subscription prompt": "Εισάγετε το email σας για να εγγραφείτε στις ενημερώσεις.",
|
||||
"move to...": "μετακίνηση στο...",
|
||||
"pin": "καρφίτσωμα",
|
||||
"published with write.as": "δημοσιεύθηκε με το write.as",
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package l10n
|
||||
|
||||
var phrasesEU = map[string]string{
|
||||
"Anonymous post": "Bidalketa anonimoa",
|
||||
"Blogs": "Blogak",
|
||||
"Enter": "Sartu",
|
||||
"Newer": "Berriagoak",
|
||||
"Older": "Zaharragoak",
|
||||
"Posts": "Bidalketak",
|
||||
"Publish to...": "Argitaratu hemen...",
|
||||
"Publish": "Argitaratu",
|
||||
"Read more...": "Irakurri gehiago...",
|
||||
"Subscribe": "Izena eman",
|
||||
"This blog requires a password.": "Blog honek pasahitza behar du.",
|
||||
"Toggle theme": "Aldatu itxura",
|
||||
"View posts": "Ikusi bidalketak",
|
||||
"delete": "ezabatu",
|
||||
"edit": "editatu",
|
||||
"email subscription prompt": "Sartu zure e-posta helbidea berriak jasotzeko.",
|
||||
"move to...": "mugitu hona...",
|
||||
"pin": "finkatu",
|
||||
"published with write.as": "write.as bidez argitaratua",
|
||||
"share modal ending": "Bidali lagun bati, partekatu sarean zehar edo agian, txiokatu. Ikasi gehiago.",
|
||||
"share modal introduction": "Argitaratutako bidalketa orok URL sekretu eta bakarra dauka, edonorekin partekatu dezakezuna. Hau da URLa:",
|
||||
"share modal title": "Partekatu bidalketa hau",
|
||||
"share": "partekatu",
|
||||
"unpin": "desfinkatu",
|
||||
}
|
||||
+17
-13
@@ -1,24 +1,28 @@
|
||||
package l10n
|
||||
|
||||
var phrasesFR = map[string]string{
|
||||
"Anonymous post": "Post anonyme",
|
||||
"Anonymous post": "Billet anonyme",
|
||||
"Blogs": "Blogs",
|
||||
"Newer": "Nouveaux",
|
||||
"Older": "Anciens",
|
||||
"Posts": "Posts",
|
||||
"Publish to...": "Publie sur...",
|
||||
"Publish": "Publie",
|
||||
"Read more...": "En savoir plus...",
|
||||
"Toggle theme": "Activer thème",
|
||||
"View posts": "Voir Posts",
|
||||
"Enter": "Valider",
|
||||
"Newer": "Récents",
|
||||
"Older": "Précédents",
|
||||
"Posts": "Billets",
|
||||
"Publish to...": "Publier sur...",
|
||||
"Publish": "Publier",
|
||||
"Read more...": "Lire la suite...",
|
||||
"Subscribe": "S'abonner",
|
||||
"This blog requires a password.": "Ce blog requiert un mot de passe.",
|
||||
"Toggle theme": "Changer de thème",
|
||||
"View posts": "Voir les billets",
|
||||
"delete": "effacer",
|
||||
"edit": "modifier",
|
||||
"email subscription prompt": "Insérer votre adresse email pour recevoir les mises à jour",
|
||||
"move to...": "déplacer vers...",
|
||||
"pin": "épingler",
|
||||
"published with write.as": "publié avec write.as",
|
||||
"share modal ending": "Envoie-le à un ami, partage-le sur le web, ou peut-être en tant que tweet. En savoir plus.",
|
||||
"share modal introduction": "Tout post publié a une adresse URL secrète et unique que tu peux partager avec qui tu veux. Voici cette URL:",
|
||||
"share modal title": "Partage ce post",
|
||||
"share modal ending": "Envoyer à un ami, partager sur le web, ou peut-être en tant que tweet. En savoir plus.",
|
||||
"share modal introduction": "Chaque billet dispose d’une adresse (URL) secrète et unique qui peut être partagée avec quelqu’un. Voici cette URL:",
|
||||
"share modal title": "Partager ce billet",
|
||||
"share": "partager",
|
||||
"unpin": "enlever",
|
||||
"unpin": "détacher",
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package l10n
|
||||
|
||||
var phrasesGL = map[string]string{
|
||||
"Anonymous post": "Publicación anónima",
|
||||
"Blogs": "Blogs",
|
||||
"Enter": "Entrar",
|
||||
"Newer": "Máis recente",
|
||||
"Older": "Máis antigo",
|
||||
"Posts": "Publicacións",
|
||||
"Publish to...": "Publicar en...",
|
||||
"Publish": "Publicar",
|
||||
"Read more...": "Saber máis...",
|
||||
"Subscribe": "Subscribir",
|
||||
"This blog requires a password.": "Este blog require un contrasinal.",
|
||||
"Toggle theme": "Cambiar decorado",
|
||||
"View posts": "Ver Publicacións",
|
||||
"delete": "eliminar",
|
||||
"edit": "editar",
|
||||
"email subscription prompt": "Escribe o teu email para recibir actualizacións.",
|
||||
"move to...": "mover a...",
|
||||
"pin": "fixar",
|
||||
"published with write.as": "publicado con write.as",
|
||||
"share modal ending": "Envíallo a un amigo, compárteo en internet e redes sociais. Saber máis.",
|
||||
"share modal introduction": "Cada publicación ten un identificador, un URL único que podes compartir con calquera. Este é o URL:",
|
||||
"share modal title": "Comparte a publicación",
|
||||
"share": "compartir",
|
||||
"unpin": "desafixar",
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package l10n
|
||||
|
||||
var phrasesHE = map[string]string{
|
||||
"Anonymous post": "פוסטים אנונימיים",
|
||||
"Blogs": "בלוגים",
|
||||
"Enter": "היכנס",
|
||||
"Newer": "חדש יותר",
|
||||
"Older": "ישן יותר",
|
||||
"Posts": "פוסטים",
|
||||
"Publish to...": "פירסום ל...",
|
||||
"Publish": "פירסום",
|
||||
"Read more...": "קרא עוד...",
|
||||
"Subscribe": "הירשם",
|
||||
"This blog requires a password.": "לבלוג זה ישנה סיסמה",
|
||||
"Toggle theme": "החלפת ערכת נושא",
|
||||
"View posts": "צפייה בפוסטים",
|
||||
"delete": "מחיקה",
|
||||
"edit": "עריכה",
|
||||
"email subscription prompt": "הכנס את המייל שלך כדי לקבל לעידכונים",
|
||||
"move to...": "העברה ל...",
|
||||
"pin": "הצמדה",
|
||||
"published with write.as": "פורסם ע''י write.as",
|
||||
"share modal ending": "שלח לחברים, פרסם ברשת, או אולי צייץ את זה. למד עוד.",
|
||||
"share modal introduction": "לכל פוסט יש קישור סודי ויחודי שניתן לשתף עם כל אחד. הנה הקישור:",
|
||||
"share modal title": "שיתוף פוסט זה",
|
||||
"share": "שיתוף",
|
||||
"unpin": "ביטול הצמדה",
|
||||
}
|
||||
+9
-5
@@ -3,21 +3,25 @@ package l10n
|
||||
var phrasesIT = map[string]string{
|
||||
"Anonymous post": "Post anonimo",
|
||||
"Blogs": "Blogs",
|
||||
"Newer": "Più recenti",
|
||||
"Older": "Più vecchi",
|
||||
"Enter": "Invio",
|
||||
"Newer": "Recenti",
|
||||
"Older": "Precedenti",
|
||||
"Posts": "Posts",
|
||||
"Publish to...": "Pubblica su...",
|
||||
"Publish": "Pubblica",
|
||||
"Read more...": "Continua...",
|
||||
"Subscribe": "Sottoscrivi",
|
||||
"This blog requires a password.": "Questo blog necessita una password.",
|
||||
"Toggle theme": "Attiva tema",
|
||||
"View posts": "Vedi Posts",
|
||||
"delete": "cancella",
|
||||
"edit": "modifica",
|
||||
"email subscription prompt": "Inserisci la tua email per ricevere aggiornamenti",
|
||||
"move to...": "sposta verso...",
|
||||
"pin": "attacca",
|
||||
"pin": "appunta",
|
||||
"published with write.as": "pubblicato con write.as",
|
||||
"share modal ending": "Mandalo ad un amico, condividilo sul web, oppure tweettalo. Per saperne di più.",
|
||||
"share modal introduction": "Ogni post pubblicato possiede un URL segreto e unico che puoi condividere con chiunque. Questo è l'URL:",
|
||||
"share modal ending": "Mandala ad un amico, condividila sul web, oppure tweettala. Per saperne di più.",
|
||||
"share modal introduction": "Ogni post pubblicato possiede una URL segreta e unica che puoi condividere con chiunque. Questa è l'URL:",
|
||||
"share modal title": "Condividi questo post",
|
||||
"share": "condividi",
|
||||
"unpin": "stacca",
|
||||
|
||||
+6
-2
@@ -3,21 +3,25 @@ package l10n
|
||||
var phrasesJA = map[string]string{
|
||||
"Anonymous post": "匿名投稿",
|
||||
"Blogs": "ブログ",
|
||||
"Enter": "認証",
|
||||
"Newer": "新しい投稿",
|
||||
"Older": "古い投稿",
|
||||
"Posts": "投稿",
|
||||
"Publish to...": "公開先…",
|
||||
"Publish": "公開",
|
||||
"Read more...": "もっと読む…",
|
||||
"Subscribe": "購読",
|
||||
"This blog requires a password.": "このブログはパスワードを必要としています。",
|
||||
"Toggle theme": "テーマを変更",
|
||||
"View posts": "投稿を見る",
|
||||
"delete": "削除",
|
||||
"edit": "編集",
|
||||
"email subscription prompt": "このブログを購読したい場合は、メールアドレスを入力してください。",
|
||||
"move to...": "移動…",
|
||||
"pin": "固定表示する",
|
||||
"published with write.as": "write.as を使って公開されました",
|
||||
"share modal ending": "友達に送信したり、ウェブの大海にシェアしたり、ツイートしたり。もっと知る。",
|
||||
"share modal introduction": "全ての投稿には秘密の、シェアするとだれでも見ることのできる固有のURLがあります。これがそのURLです:",
|
||||
"share modal ending": "友達に送信したり、Web 上で共有したり、ツイートすることが出来ます。もっと詳しく。",
|
||||
"share modal introduction": "全ての投稿には秘密の、シェアするとだれでも見ることのできる固有の URL があります。これがその URL です:",
|
||||
"share modal title": "投稿をシェアする",
|
||||
"share": "シェア",
|
||||
"unpin": "固定表示をやめる",
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
package l10n
|
||||
|
||||
var phrasesLT = map[string]string{
|
||||
"Anonymous post": "Anoniminis įrašas",
|
||||
"Blogs": "Tinklaraščiai",
|
||||
"Enter": "Įvesti",
|
||||
"Newer": "Naujesni",
|
||||
"Older": "Senesni",
|
||||
"Posts": "Įrašai",
|
||||
"Publish to...": "Publikuoti į...",
|
||||
"Publish": "Publikuoti",
|
||||
"Read more...": "Skaityti daugiau...",
|
||||
"This blog requires a password.": "Šis tinklaraštis reikalauja slaptažodžio.",
|
||||
"Toggle theme": "Keisti temą",
|
||||
"View posts": "Peržiūrėti įrašus",
|
||||
"delete": "ištrinti",
|
||||
"edit": "koreguoti",
|
||||
"move to...": "perkelti į...",
|
||||
"pin": "prisegti",
|
||||
"published with write.as": "publikuojama su write.as",
|
||||
"share modal ending": "Siųskite draugui, dalinkitės internete ar per Twitter. Sužinokite daugiau.",
|
||||
"share modal introduction": "Kiekvienas publikuotas įrašas turi slaptą, unikalų URL kuriuo galite pasidalinti su bet kuo. Šis URL yra:",
|
||||
"share modal title": "Dalintis šiuo įrašu",
|
||||
"share": "dalintis",
|
||||
"unpin": "atsegti",
|
||||
"title dash": "–",
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package l10n
|
||||
|
||||
var phrasesNL = map[string]string{
|
||||
"Anonymous post": "Anoniem artikel",
|
||||
"Blogs": "Blogs",
|
||||
"Enter": "Invoeren",
|
||||
"Newer": "Nieuwer",
|
||||
"Older": "Ouder",
|
||||
"Posts": "Artikelen",
|
||||
"Publish to...": "Publiceren op...",
|
||||
"Publish": "Publiceren",
|
||||
"Read more...": "Lees verder...",
|
||||
"Subscribe": "Abonneren",
|
||||
"This blog requires a password.": "Voor dit blog is een wachtwoord vereist.",
|
||||
"Toggle theme": "Ander thema",
|
||||
"View posts": "Artikelen bekijken",
|
||||
"delete": "verwijderen",
|
||||
"edit": "bewerken",
|
||||
"email subscription prompt": "Voer je e-mailadres in om te abonneren op updates.",
|
||||
"move to...": "verplaatsen naar...",
|
||||
"pin": "vastmaken",
|
||||
"published with write.as": "gepubliceerd met write.as",
|
||||
"share modal ending": "Deel de link met een vriend, op het internet of op Twitter. Meer informatie.",
|
||||
"share modal introduction": "Elk gepubliceerd artikel bevat een geheime, unieke link die je met iedereen kunt delen. Dit is de link:",
|
||||
"share modal title": "Deel dit artikel",
|
||||
"share": "delen",
|
||||
"unpin": "losmaken",
|
||||
}
|
||||
+3
-1
@@ -3,18 +3,20 @@ package l10n
|
||||
var phrasesZH = map[string]string{
|
||||
"Anonymous post": "匿名文章",
|
||||
"Blogs": "博客",
|
||||
"Enter": "按下Enter按钮",
|
||||
"Enter": "进入",
|
||||
"Newer": "最近的博客",
|
||||
"Older": "之前的博客",
|
||||
"Posts": "文章",
|
||||
"Publish to...": "发布到...",
|
||||
"Publish": "发布",
|
||||
"Read more...": "阅读更多",
|
||||
"Subscribe": "订阅",
|
||||
"This blog requires a password.": "这篇博客需要密码",
|
||||
"Toggle theme": "更换主题",
|
||||
"View posts": "查看文章",
|
||||
"delete": "删除",
|
||||
"edit": "编辑",
|
||||
"email subscription prompt": "输入邮件地址,订阅更新",
|
||||
"move to...": "移动到",
|
||||
"pin": "固定文章",
|
||||
"published with write.as": "用write.as来发布",
|
||||
|
||||
@@ -6,6 +6,10 @@ func Strings(lang string) map[string]string {
|
||||
switch lang {
|
||||
case "ar":
|
||||
return phrasesAR
|
||||
case "cs":
|
||||
return phrasesCS
|
||||
case "da":
|
||||
return phrasesDA
|
||||
case "de":
|
||||
return phrasesDE
|
||||
case "el":
|
||||
@@ -14,18 +18,28 @@ func Strings(lang string) map[string]string {
|
||||
return phrasesEO
|
||||
case "es":
|
||||
return phrasesES
|
||||
case "eu":
|
||||
return phrasesEU
|
||||
case "fa":
|
||||
return phrasesFA
|
||||
case "fr":
|
||||
return phrasesFR
|
||||
case "gl":
|
||||
return phrasesGL
|
||||
case "he":
|
||||
return phrasesHE
|
||||
case "hu":
|
||||
return phrasesHU
|
||||
case "it":
|
||||
return phrasesIT
|
||||
case "ja":
|
||||
return phrasesJA
|
||||
case "lt":
|
||||
return phrasesLT
|
||||
case "mk":
|
||||
return phrasesMK
|
||||
case "nl":
|
||||
return phrasesNL
|
||||
case "pl":
|
||||
return phrasesPL
|
||||
case "pt":
|
||||
|
||||
+17
-2
@@ -2,8 +2,10 @@
|
||||
package log
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"runtime"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -13,7 +15,7 @@ var (
|
||||
|
||||
func init() {
|
||||
InfoLog = log.New(os.Stdout, "", log.Ldate|log.Ltime)
|
||||
ErrorLog = log.New(os.Stderr, "ERROR: ", log.Ldate|log.Ltime|log.Lshortfile)
|
||||
ErrorLog = log.New(os.Stderr, "ERROR: ", log.Ldate|log.Ltime)
|
||||
}
|
||||
|
||||
// Info logs an informational message to Stdout.
|
||||
@@ -23,5 +25,18 @@ func Info(s string, v ...interface{}) {
|
||||
|
||||
// Error logs an error to Stderr.
|
||||
func Error(s string, v ...interface{}) {
|
||||
ErrorLog.Printf(s, v...)
|
||||
// Include original caller information
|
||||
_, file, line, _ := runtime.Caller(1)
|
||||
|
||||
// Determine short filename (from standard log package)
|
||||
short := file
|
||||
for i := len(file) - 1; i > 0; i-- {
|
||||
if file[i] == '/' {
|
||||
short = file[i+1:]
|
||||
break
|
||||
}
|
||||
}
|
||||
file = short
|
||||
|
||||
ErrorLog.Printf(fmt.Sprintf("%s:%d: ", short, line)+s, v...)
|
||||
}
|
||||
|
||||
@@ -67,3 +67,13 @@ func (memo *Memo) Get() (value interface{}, err error) {
|
||||
}
|
||||
return memo.cache.res.value, memo.cache.res.err
|
||||
}
|
||||
|
||||
// Reset forcibly resets the cache to nil without checking if the cache
|
||||
// duration has elapsed.
|
||||
func (memo *Memo) Reset() {
|
||||
defer memo.mu.Unlock()
|
||||
memo.mu.Lock()
|
||||
|
||||
memo.cache = nil
|
||||
memo.lastCache = time.Now()
|
||||
}
|
||||
|
||||
+7
-7
@@ -1,4 +1,4 @@
|
||||
// Package passgen generates random, unmemorable passwords.
|
||||
// Package passgen generates random passwords.
|
||||
//
|
||||
// Example usage:
|
||||
//
|
||||
@@ -19,20 +19,20 @@ const DefLen = 20
|
||||
// DefChars is the default set of characters used in the password.
|
||||
var DefChars = []byte("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()- _=+,.?/:;{}[]`~")
|
||||
|
||||
// New returns a random password of the default length with the default set of
|
||||
// characters.
|
||||
// New returns a random, unmemorable password of the default length with the
|
||||
// default set of characters.
|
||||
func New() string {
|
||||
return NewLenChars(DefLen, DefChars)
|
||||
}
|
||||
|
||||
// NewLen returns a random password of the given length with the default set
|
||||
// of characters.
|
||||
// NewLen returns a random, unmemorable password of the given length with the
|
||||
// default set of characters.
|
||||
func NewLen(length int) string {
|
||||
return NewLenChars(length, DefChars)
|
||||
}
|
||||
|
||||
// NewLenChars returns a random password of the given length with the given
|
||||
// set of characters.
|
||||
// NewLenChars returns a random, unmemorable password of the given length with
|
||||
// the given set of characters.
|
||||
func NewLenChars(length int, chars []byte) string {
|
||||
if length == 0 {
|
||||
return ""
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
package passgen
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"math/big"
|
||||
)
|
||||
|
||||
var (
|
||||
ar = []rune("aA4")
|
||||
cr = []rune("cC")
|
||||
er = []rune("eE3")
|
||||
fr = []rune("fF")
|
||||
gr = []rune("gG")
|
||||
hr = []rune("hH")
|
||||
ir = []rune("iI1")
|
||||
lr = []rune("lL")
|
||||
nr = []rune("nN")
|
||||
or = []rune("oO0")
|
||||
rr = []rune("rR")
|
||||
sr = []rune("sS5")
|
||||
tr = []rune("tT7")
|
||||
remr = []rune("bcdfghjklmnpqrstvwxyzBCDFGHJKLMNPQRSTVWXYZ0123456789")
|
||||
)
|
||||
|
||||
// NewWordish generates a password made of word-like words.
|
||||
func NewWordish() string {
|
||||
b := []rune{}
|
||||
b = append(b, randLetter(cr))
|
||||
b = append(b, randLetter(hr))
|
||||
b = append(b, randLetter(ar))
|
||||
b = append(b, randLetter(nr))
|
||||
b = append(b, randLetter(gr))
|
||||
b = append(b, randLetter(er))
|
||||
b = append(b, randLetter(tr))
|
||||
b = append(b, randLetter(hr))
|
||||
b = append(b, randLetter(ir))
|
||||
b = append(b, randLetter(sr))
|
||||
b = append(b, randLetter(ar))
|
||||
b = append(b, randLetter(fr))
|
||||
b = append(b, randLetter(tr))
|
||||
b = append(b, randLetter(er))
|
||||
b = append(b, randLetter(rr))
|
||||
b = append(b, randLetter(lr))
|
||||
b = append(b, randLetter(or))
|
||||
b = append(b, randLetter(gr))
|
||||
b = append(b, randLetter(gr))
|
||||
b = append(b, randLetter(ir))
|
||||
b = append(b, randLetter(nr))
|
||||
b = append(b, randLetter(gr))
|
||||
b = append(b, randLetter(ir))
|
||||
b = append(b, randLetter(nr))
|
||||
for i := 0; i <= 7; i++ {
|
||||
b = append(b, randLetter(remr))
|
||||
}
|
||||
return string(b)
|
||||
}
|
||||
|
||||
func randLetter(l []rune) rune {
|
||||
li, err := rand.Int(rand.Reader, big.NewInt(int64(len(l))))
|
||||
if err != nil {
|
||||
return rune(-1)
|
||||
}
|
||||
return l[li.Int64()]
|
||||
}
|
||||
+146
@@ -1,9 +1,28 @@
|
||||
package posts
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
stripmd "github.com/writeas/go-strip-markdown"
|
||||
"github.com/writeas/web-core/stringmanip"
|
||||
"regexp"
|
||||
"strings"
|
||||
"unicode"
|
||||
"unicode/utf8"
|
||||
)
|
||||
|
||||
const (
|
||||
maxTitleLen = 80
|
||||
assumedTitleLen = 80
|
||||
)
|
||||
|
||||
var (
|
||||
titleElementReg = regexp.MustCompile("</?p>")
|
||||
urlReg = regexp.MustCompile("https?://")
|
||||
imgReg = regexp.MustCompile(`!\[([^]]+)\]\([^)]+\)`)
|
||||
)
|
||||
|
||||
// ExtractTitle takes the given raw post text and returns a title, if explicitly
|
||||
// provided, and a body.
|
||||
func ExtractTitle(content string) (title string, body string) {
|
||||
if hashIndex := strings.Index(content, "# "); hashIndex == 0 {
|
||||
eol := strings.IndexRune(content, '\n')
|
||||
@@ -17,3 +36,130 @@ func ExtractTitle(content string) (title string, body string) {
|
||||
body = content
|
||||
return
|
||||
}
|
||||
|
||||
func FriendlyPostTitle(content, friendlyId string) string {
|
||||
content = StripHTMLWithoutEscaping(content)
|
||||
|
||||
content = strings.TrimLeftFunc(stripmd.Strip(content), unicode.IsSpace)
|
||||
eol := strings.IndexRune(content, '\n')
|
||||
blankLine := strings.Index(content, "\n\n")
|
||||
if blankLine != -1 && blankLine <= eol && blankLine <= assumedTitleLen {
|
||||
return strings.TrimSpace(content[:blankLine])
|
||||
} else if eol == -1 && utf8.RuneCountInString(content) <= maxTitleLen {
|
||||
return content
|
||||
}
|
||||
|
||||
title, truncd := TruncToWord(PostLede(content, true), maxTitleLen)
|
||||
if truncd {
|
||||
title += "..."
|
||||
}
|
||||
return title
|
||||
}
|
||||
|
||||
// PostDescription generates a description based on the given post content,
|
||||
// title, and post ID. This doesn't consider a V2 post field, `title` when
|
||||
// choosing what to generate. In case a post has a title, this function will
|
||||
// fail, and logic should instead be implemented to skip this when there's no
|
||||
// title, like so:
|
||||
// var desc string
|
||||
// if title == "" {
|
||||
// desc = PostDescription(content, title, friendlyId)
|
||||
// } else {
|
||||
// desc = ShortPostDescription(content)
|
||||
// }
|
||||
func PostDescription(content, title, friendlyId string) string {
|
||||
maxLen := 140
|
||||
|
||||
if content == "" {
|
||||
content = "WriteFreely is a painless, simple, federated blogging platform."
|
||||
} else {
|
||||
fmtStr := "%s"
|
||||
truncation := 0
|
||||
if utf8.RuneCountInString(content) > maxLen {
|
||||
// Post is longer than the max description, so let's show a better description
|
||||
fmtStr = "%s..."
|
||||
truncation = 3
|
||||
}
|
||||
|
||||
if title == friendlyId {
|
||||
// No specific title was found; simply truncate the post, starting at the beginning
|
||||
content = fmt.Sprintf(fmtStr, strings.Replace(stringmanip.Substring(content, 0, maxLen-truncation), "\n", " ", -1))
|
||||
} else {
|
||||
// There was a title, so return a real description
|
||||
blankLine := strings.Index(content, "\n\n")
|
||||
if blankLine < 0 {
|
||||
blankLine = 0
|
||||
}
|
||||
truncd := stringmanip.Substring(content, blankLine, blankLine+maxLen-truncation)
|
||||
contentNoNL := strings.Replace(truncd, "\n", " ", -1)
|
||||
content = strings.TrimSpace(fmt.Sprintf(fmtStr, contentNoNL))
|
||||
}
|
||||
}
|
||||
|
||||
return content
|
||||
}
|
||||
|
||||
func ShortPostDescription(content string) string {
|
||||
maxLen := 140
|
||||
fmtStr := "%s"
|
||||
truncation := 0
|
||||
if utf8.RuneCountInString(content) > maxLen {
|
||||
// Post is longer than the max description, so let's show a better description
|
||||
fmtStr = "%s..."
|
||||
truncation = 3
|
||||
}
|
||||
return strings.TrimSpace(fmt.Sprintf(fmtStr, strings.Replace(stringmanip.Substring(content, 0, maxLen-truncation), "\n", " ", -1)))
|
||||
}
|
||||
|
||||
// TruncToWord truncates the given text to the provided limit.
|
||||
func TruncToWord(s string, l int) (string, bool) {
|
||||
truncated := false
|
||||
c := []rune(s)
|
||||
if len(c) > l {
|
||||
truncated = true
|
||||
s = string(c[:l])
|
||||
spaceIdx := strings.LastIndexByte(s, ' ')
|
||||
if spaceIdx > -1 {
|
||||
s = s[:spaceIdx]
|
||||
}
|
||||
}
|
||||
return s, truncated
|
||||
}
|
||||
|
||||
// PostLede attempts to extract the first thought of the given post, generally
|
||||
// contained within the first line or sentence of text.
|
||||
func PostLede(t string, includePunc bool) string {
|
||||
// Adjust where we truncate if we want to include punctuation
|
||||
iAdj := 0
|
||||
if includePunc {
|
||||
iAdj = 1
|
||||
}
|
||||
|
||||
// Find lede within first line of text
|
||||
nl := strings.IndexRune(t, '\n')
|
||||
if nl > -1 {
|
||||
t = t[:nl]
|
||||
}
|
||||
|
||||
// Strip certain HTML tags
|
||||
t = titleElementReg.ReplaceAllString(t, "")
|
||||
|
||||
// Strip URL protocols
|
||||
t = urlReg.ReplaceAllString(t, "")
|
||||
|
||||
// Strip image URL, leaving only alt text
|
||||
t = imgReg.ReplaceAllString(t, " $1 ")
|
||||
|
||||
// Find lede within first sentence
|
||||
punc := strings.Index(t, ". ")
|
||||
if punc > -1 {
|
||||
t = t[:punc+iAdj]
|
||||
}
|
||||
punc = stringmanip.IndexRune(t, '。')
|
||||
if punc > -1 {
|
||||
c := []rune(t)
|
||||
t = string(c[:punc+iAdj])
|
||||
}
|
||||
|
||||
return t
|
||||
}
|
||||
|
||||
@@ -33,3 +33,45 @@ Yep.`},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestPostLede(t *testing.T) {
|
||||
text := map[string]string{
|
||||
"早安。跨出舒適圈,才能前往": "早安。",
|
||||
"早安。This is my post. It is great.": "早安。",
|
||||
"Hello. 早安。": "Hello.",
|
||||
"Sup? Everyone says punctuation is punctuation.": "Sup?",
|
||||
"Humans are humans, and society is full of good and bad actors. Technology, at the most fundamental level, is a neutral tool that can be used by either to meet any ends. ": "Humans are humans, and society is full of good and bad actors.",
|
||||
`Online Domino Is Must For Everyone
|
||||
|
||||
Do you want to understand how to play poker online?`: "Online Domino Is Must For Everyone",
|
||||
`おはようございます
|
||||
|
||||
私は日本から帰ったばかりです。`: "おはようございます",
|
||||
"Hello, we say, おはよう. We say \"good morning\"": "Hello, we say, おはよう.",
|
||||
}
|
||||
|
||||
c := 1
|
||||
for i, o := range text {
|
||||
if s := PostLede(i, true); s != o {
|
||||
t.Errorf("#%d: Got '%s' from '%s'; expected '%s'", c, s, i, o)
|
||||
}
|
||||
c++
|
||||
}
|
||||
}
|
||||
|
||||
func TestTruncToWord(t *testing.T) {
|
||||
text := map[string]string{
|
||||
"Можливо, ми можемо використовувати інтернет-інструменти, щоб виготовити якийсь текст, який би міг бути і на, і в кінцевому підсумку, буде скорочено, тому що це тривало так довго.": "Можливо, ми можемо використовувати інтернет-інструменти, щоб виготовити якийсь",
|
||||
"早安。This is my post. It is great. It is a long post that is great that is a post that is great.": "早安。This is my post. It is great. It is a long post that is great that is a post",
|
||||
"Sup? Everyone says punctuation is punctuation.": "Sup? Everyone says punctuation is punctuation.",
|
||||
"I arrived in Japan six days ago. Tired from a 10-hour flight after a night-long layover in Calgary, I wandered wide-eyed around Narita airport looking for an ATM.": "I arrived in Japan six days ago. Tired from a 10-hour flight after a night-long",
|
||||
}
|
||||
|
||||
c := 1
|
||||
for i, o := range text {
|
||||
if s, _ := TruncToWord(i, 80); s != o {
|
||||
t.Errorf("#%d: Got '%s' from '%s'; expected '%s'", c, s, i, o)
|
||||
}
|
||||
c++
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package posts
|
||||
import (
|
||||
"github.com/microcosm-cc/bluemonday"
|
||||
"github.com/writeas/saturday"
|
||||
"html"
|
||||
"regexp"
|
||||
"strings"
|
||||
"unicode"
|
||||
@@ -61,3 +62,37 @@ func ApplyBasicMarkdown(data []byte) string {
|
||||
|
||||
return outHTML
|
||||
}
|
||||
|
||||
// ApplyBasicAccessibleMarkdown applies Markdown to the given data, rendering basic text formatting and preserving hard
|
||||
// line breaks in HTML. It is meant for formatting text in small, multi-line UI elements, like user profile biographies.
|
||||
func ApplyBasicAccessibleMarkdown(data []byte) string {
|
||||
mdExtensions := 0 |
|
||||
blackfriday.EXTENSION_STRIKETHROUGH |
|
||||
blackfriday.EXTENSION_SPACE_HEADERS |
|
||||
blackfriday.EXTENSION_HEADER_IDS |
|
||||
blackfriday.EXTENSION_HARD_LINE_BREAK
|
||||
htmlFlags := 0 |
|
||||
blackfriday.HTML_USE_SMARTYPANTS |
|
||||
blackfriday.HTML_USE_XHTML |
|
||||
blackfriday.HTML_SMARTYPANTS_DASHES
|
||||
|
||||
// Generate Markdown
|
||||
md := blackfriday.Markdown([]byte(data), blackfriday.HtmlRenderer(htmlFlags, "", ""), mdExtensions)
|
||||
// Strip out bad HTML
|
||||
policy := bluemonday.UGCPolicy()
|
||||
policy.AllowAttrs("class", "id").Globally()
|
||||
policy.AllowAttrs("rel").OnElements("a")
|
||||
policy.RequireNoFollowOnLinks(false)
|
||||
outHTML := string(policy.SanitizeBytes(md))
|
||||
// Strip surrounding <p> tags that blackfriday adds
|
||||
outHTML = markeddownReg.ReplaceAllString(outHTML, "$1")
|
||||
outHTML = strings.TrimRightFunc(outHTML, unicode.IsSpace)
|
||||
|
||||
return outHTML
|
||||
}
|
||||
|
||||
// StripHTMLWithoutEscaping strips HTML tags with bluemonday's StrictPolicy, then unescapes the HTML
|
||||
// entities added in by sanitizing the content.
|
||||
func StripHTMLWithoutEscaping(content string) string {
|
||||
return html.UnescapeString(bluemonday.StrictPolicy().Sanitize(content))
|
||||
}
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
package silobridge
|
||||
|
||||
// fakeAPInstances contains a list of sites that we allow writers to mention
|
||||
// with the @handle@instance.tld syntax, plus the corresponding prefix to
|
||||
// insert between `https://instance.tld/` and `handle` (e.g.
|
||||
// https://medium.com/@handle)
|
||||
var fakeAPInstances = map[string]string{
|
||||
"deviantart.com": "",
|
||||
"facebook.com": "",
|
||||
"flickr.com": "photos/",
|
||||
"github.com": "",
|
||||
"instagram.com": "",
|
||||
"medium.com": "@",
|
||||
"reddit.com": "user/",
|
||||
"twitter.com": "",
|
||||
"wattpad.com": "user/",
|
||||
"youtube.com": "user/",
|
||||
}
|
||||
|
||||
// Profile returns the full profile URL for a fake ActivityPub instance, based
|
||||
// on the given handle and domain. If the domain isn't recognized, an empty
|
||||
// string is returned.
|
||||
func Profile(handle, domain string) string {
|
||||
prefix, ok := fakeAPInstances[domain]
|
||||
if !ok {
|
||||
return ""
|
||||
}
|
||||
return "https://" + domain + "/" + prefix + handle
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
package stringmanip
|
||||
|
||||
/*
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2016 Sergey Kamardin
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
// Source: https://github.com/gobwas/glob/blob/master/util/runes/runes.go
|
||||
|
||||
func IndexRune(str string, r rune) int {
|
||||
s := []rune(str)
|
||||
for i, c := range s {
|
||||
if c == r {
|
||||
return i
|
||||
}
|
||||
}
|
||||
return -1
|
||||
}
|
||||
|
||||
func LastIndexRune(str string, needle rune) int {
|
||||
s := []rune(str)
|
||||
needles := []rune{needle}
|
||||
ls, ln := len(s), len(needles)
|
||||
|
||||
switch {
|
||||
case ln == 0:
|
||||
if ls == 0 {
|
||||
return 0
|
||||
}
|
||||
return ls
|
||||
case ln == 1:
|
||||
return IndexLastRune(s, needles[0])
|
||||
case ln == ls:
|
||||
if EqualRunes(s, needles) {
|
||||
return 0
|
||||
}
|
||||
return -1
|
||||
case ln > ls:
|
||||
return -1
|
||||
}
|
||||
|
||||
head:
|
||||
for i := ls - 1; i >= 0 && i >= ln; i-- {
|
||||
for y := ln - 1; y >= 0; y-- {
|
||||
if s[i-(ln-y-1)] != needles[y] {
|
||||
continue head
|
||||
}
|
||||
}
|
||||
|
||||
return i - ln + 1
|
||||
}
|
||||
|
||||
return -1
|
||||
}
|
||||
|
||||
func IndexLastRune(s []rune, r rune) int {
|
||||
for i := len(s) - 1; i >= 0; i-- {
|
||||
if s[i] == r {
|
||||
return i
|
||||
}
|
||||
}
|
||||
|
||||
return -1
|
||||
}
|
||||
|
||||
func EqualRunes(a, b []rune) bool {
|
||||
if len(a) == len(b) {
|
||||
for i := 0; i < len(a); i++ {
|
||||
if a[i] != b[i] {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package stringmanip
|
||||
|
||||
// Substring provides a safe way to extract a substring from a UTF-8 string.
|
||||
// From this discussion:
|
||||
// https://groups.google.com/d/msg/golang-nuts/cGq1Irv_5Vs/0SKoj49BsWQJ
|
||||
func Substring(s string, p, l int) string {
|
||||
if p < 0 || l <= 0 {
|
||||
return ""
|
||||
}
|
||||
c := []rune(s)
|
||||
if p > len(c) {
|
||||
return ""
|
||||
} else if p+l > len(c) || p+l < p {
|
||||
return string(c[p:])
|
||||
}
|
||||
return string(c[p : p+l])
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
// Package tags supports operations around hashtags in plain text content
|
||||
package tags
|
||||
|
||||
import (
|
||||
"github.com/kylemcc/twitter-text-go/extract"
|
||||
)
|
||||
|
||||
// Extract finds all hashtags in the given string and returns a de-duplicated
|
||||
// list of them.
|
||||
func Extract(body string) []string {
|
||||
matches := extract.ExtractHashtags(body)
|
||||
tags := map[string]bool{}
|
||||
for i := range matches {
|
||||
// Second value (whether or not there's a hashtag) ignored here, since
|
||||
// we're only extracting hashtags.
|
||||
ht, _ := matches[i].Hashtag()
|
||||
tags[ht] = true
|
||||
}
|
||||
|
||||
resTags := make([]string, 0)
|
||||
for k := range tags {
|
||||
resTags = append(resTags, k)
|
||||
}
|
||||
return resTags
|
||||
}
|
||||
Reference in New Issue
Block a user