2022-08-09 15:25:22 +00:00
|
|
|
package plugintypes
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"database/sql"
|
2023-02-24 15:50:46 +00:00
|
|
|
"io"
|
2023-01-30 22:24:22 +00:00
|
|
|
"net/http"
|
2022-08-12 10:48:16 +00:00
|
|
|
)
|
2022-08-09 15:25:22 +00:00
|
|
|
|
|
|
|
// App is used to access GoBlog's app instance.
|
|
|
|
type App interface {
|
2023-01-23 19:30:47 +00:00
|
|
|
// Get access to GoBlog's database
|
2022-08-09 15:25:22 +00:00
|
|
|
GetDatabase() Database
|
2023-01-23 19:30:47 +00:00
|
|
|
// Get a post from the database or an error when there is no post for the given path
|
|
|
|
GetPost(path string) (Post, error)
|
2023-03-24 20:25:20 +00:00
|
|
|
// Get a blog and a bool whether it exists
|
|
|
|
GetBlog(name string) (Blog, bool)
|
2023-01-30 22:24:22 +00:00
|
|
|
// Purge the rendering cache
|
|
|
|
PurgeCache()
|
|
|
|
// Get the HTTP client used by GoBlog
|
|
|
|
GetHTTPClient() *http.Client
|
2023-02-24 15:50:46 +00:00
|
|
|
// Compile an asset (like CSS, JS, etc.) and add it to use when rendering, for some filetypes, it also get's compressed
|
|
|
|
CompileAsset(filename string, reader io.Reader) error
|
|
|
|
// Get the asset path with the filename used when compiling the assert
|
|
|
|
AssetPath(filename string) string
|
2023-03-24 20:25:20 +00:00
|
|
|
// Set parameter values for a post path
|
|
|
|
SetPostParameter(path string, parameter string, values []string) error
|
|
|
|
// Render markdown as text (without HTML)
|
|
|
|
RenderMarkdownAsText(markdown string) (text string, err error)
|
2022-08-09 15:25:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Database is used to provide access to GoBlog's database.
|
|
|
|
type Database interface {
|
|
|
|
Exec(string, ...any) (sql.Result, error)
|
|
|
|
ExecContext(context.Context, string, ...any) (sql.Result, error)
|
|
|
|
Query(string, ...any) (*sql.Rows, error)
|
|
|
|
QueryContext(context.Context, string, ...any) (*sql.Rows, error)
|
|
|
|
QueryRow(string, ...any) (*sql.Row, error)
|
|
|
|
QueryRowContext(context.Context, string, ...any) (*sql.Row, error)
|
|
|
|
}
|
|
|
|
|
2023-03-24 20:25:20 +00:00
|
|
|
// Post contains methods to access the post's data.
|
2022-08-12 10:48:16 +00:00
|
|
|
type Post interface {
|
2023-01-23 19:30:47 +00:00
|
|
|
// Get the post path
|
|
|
|
GetPath() string
|
2023-03-24 20:25:20 +00:00
|
|
|
// Get the blog name
|
|
|
|
GetBlog() string
|
2023-01-23 19:30:47 +00:00
|
|
|
// Get a string array map with all the post's parameters
|
2022-08-12 10:48:16 +00:00
|
|
|
GetParameters() map[string][]string
|
2023-03-10 14:14:50 +00:00
|
|
|
// Get a single parameter array (a parameter can have multiple values)
|
|
|
|
GetParameter(parameter string) []string
|
2023-03-24 20:25:20 +00:00
|
|
|
// Get the first value of a post parameter
|
|
|
|
GetFirstParameterValue(parameter string) string
|
2023-01-23 19:30:47 +00:00
|
|
|
// Get the post section name
|
|
|
|
GetSection() string
|
|
|
|
// Get the published date string
|
|
|
|
GetPublished() string
|
|
|
|
// Get the updated date string
|
|
|
|
GetUpdated() string
|
2023-03-10 14:14:50 +00:00
|
|
|
// Get the post content (markdown)
|
|
|
|
GetContent() string
|
2023-03-24 20:25:20 +00:00
|
|
|
// Get the post title
|
|
|
|
GetTitle() string
|
|
|
|
}
|
|
|
|
|
|
|
|
// Blog contains methods to access the blog's configuration.
|
|
|
|
type Blog interface {
|
|
|
|
// Get the language
|
|
|
|
GetLanguage() string
|
2022-08-09 15:25:22 +00:00
|
|
|
}
|
|
|
|
|
2023-03-24 20:25:20 +00:00
|
|
|
// RenderContext gives some context of the current rendering.
|
2023-01-23 19:30:47 +00:00
|
|
|
type RenderContext interface {
|
|
|
|
// Get the path of the request
|
|
|
|
GetPath() string
|
2023-03-10 14:14:50 +00:00
|
|
|
// Get the URL
|
|
|
|
GetURL() string
|
2023-01-23 19:30:47 +00:00
|
|
|
// Get the blog name
|
2022-10-31 09:52:35 +00:00
|
|
|
GetBlog() string
|
|
|
|
}
|