Documentation ¶
Overview ¶
Copyright © 2019, 2023 M.Watermann, 10247 Berlin, Germany
All rights reserved EMail : <support@mwat.de>
Package nele implements a simple blog-server.
Copyright © 2019, 2020 M.Watermann, 10247 Berlin, Germany All rights reserved EMail : <support@mwat.de>
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.
This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
You should have received a copy of the GNU General Public License along with this program. If not, see the [GNU General Public License](http://www.gnu.org/licenses/gpl.html) for details.
Copyright © 2019, 2023 M.Watermann, 10247 Berlin, Germany All rights reserved EMail : <support@mwat.de> Copyright © 2019, 2022 M.Watermann, 10247 Berlin, Germany All rights reserved EMail : <support@mwat.de>
Copyright © 2022, 2023 M.Watermann, 10247 Berlin, Germany
All rights reserved EMail : <support@mwat.de> Copyright © 2019, 2022 M.Watermann, 10247 Berlin, Germany All rights reserved EMail : <support@mwat.de>
Index ¶
- func AddConsolePost() (int, error)
- func AddFilePost(aFilename string) (int, error)
- func AddTagID(aList *hashtags.THashList, aPosting *TPosting)
- func CreateScreenshot(aURL string)
- func InitConfig()
- func InitHashlist(aList *hashtags.THashList)
- func MDtoHTML(aMarkdown []byte) (rHTML []byte)
- func MarkupCloud(aList *hashtags.THashList) []template.HTML
- func MarkupTags(aPage []byte) []byte
- func NewID() string
- func PostingBaseDirectory() string
- func PostingCount() (rCount uint32)
- func PrepareLinkScreenshots(aPosting *TPosting)
- func ReadHashlist(aList *hashtags.THashList)
- func RemoveIDTags(aList *hashtags.THashList, aID string)
- func RemovePageScreenshots(aPosting *TPosting)
- func RenameIDTags(aList *hashtags.THashList, aOldID, aNewID string)
- func ReplaceTag(aList *hashtags.THashList, aSearchTag, aReplaceTag string)
- func SetPostingBaseDirectory(aBaseDir string)
- func ShowHelp()
- func URLparts(aURL string) (rDir, rPath string)
- func UpdateScreenshots(aPostingBaseDir string)
- func UpdateTags(aList *hashtags.THashList, aPosting *TPosting)
- func UserAdd(aUser, aFilename string)
- func UserCheck(aUser, aFilename string)
- func UserDelete(aUser, aFilename string)
- func UserList(aFilename string)
- func UserUpdate(aUser, aFilename string)
- type TAppArgs
- type TPageHandler
- type TPostList
- func (pl *TPostList) Add(aPosting *TPosting) *TPostList
- func (pl *TPostList) Day() *TPostList
- func (pl *TPostList) Delete(aPosting *TPosting) (*TPostList, bool)
- func (pl *TPostList) Index(aPosting *TPosting) int
- func (pl *TPostList) IsSorted() bool
- func (pl *TPostList) Len() int
- func (pl *TPostList) Month(aYear int, aMonth time.Month) *TPostList
- func (pl *TPostList) Newest(aNumber, aStart int) error
- func (pl *TPostList) Sort() *TPostList
- func (pl *TPostList) Week(aYear int, aMonth time.Month, aDay int) *TPostList
- type TPosting
- func (p *TPosting) After(aID string) bool
- func (p *TPosting) Before(aID string) bool
- func (p *TPosting) Clear() *TPosting
- func (p *TPosting) Date() string
- func (p *TPosting) Delete() error
- func (p *TPosting) Equal(aID string) bool
- func (p *TPosting) Exists() bool
- func (p *TPosting) ID() string
- func (p *TPosting) LastModified() string
- func (p *TPosting) Len() int
- func (p *TPosting) Load() error
- func (p *TPosting) Markdown() []byte
- func (p *TPosting) PathFileName() string
- func (p *TPosting) Post() template.HTML
- func (p *TPosting) Set(aMarkdown []byte) *TPosting
- func (p *TPosting) Store() (int, error)
- func (p *TPosting) String() string
- func (p *TPosting) Time() time.Time
- type TView
- type TViewList
- type TemplateData
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddConsolePost ¶
AddConsolePost reads data from `StdIn` and saves it as a new posting, returning the number of bytes written and a possible I/O error.
func AddFilePost ¶
AddFilePost reads `aFilename` and adds it as a new posting, returning the number of bytes written and a possible I/O error.
`aFilename` The text file to add as a new posting.
func AddTagID ¶
AddTagID checks a newly added `aPosting` for #hashtags and @mentions.
`aList` The hashlist to use (update). `aPosting` The new posting to handle.
func CreateScreenshot ¶ added in v0.18.0
func CreateScreenshot(aURL string)
CreateScreenshot generates a screenshot of `aURL` in background.
`aURL` The URL for which to create a screenshot image.
func InitConfig ¶
func InitConfig()
InitConfig reads both the INI values and the commandline arguments.
The steps here are:
(1) read the INI file(s):
(a) read the local `./.nele.ini`, (b) read the global `/etc/nele.ini`, (c) read the user-local `~/.nele.ini`, (d) read the user-local `~/.config/nele.ini`,
(2) merge the commandline arguments with the INI values into the global `AppArgs` variable.
This function is meant to be called first thing in the application's `main()` function.
func InitHashlist ¶
InitHashlist initialises the hash list.
`aList` The list of #hashtags/@mentions to update.
func MDtoHTML ¶
MDtoHTML converts the `aMarkdown` data and returns HTML data.
`aMarkdown` The raw Markdown text to convert.
func MarkupCloud ¶
MarkupCloud returns a list with the markup of all existing #hashtags/@mentions.
`aList` The list of #hashtags/@mentions to use.
func MarkupTags ¶
MarkupTags returns `aPage` with all #hashtags/@mentions marked up as a HREF links.
`aPage` The HTML page to process.
func NewID ¶
func NewID() string
NewID returns a new article ID. It is based on the current date/time and given in hexadecimal notation. It's assumed that no more than one ID per nanosecond is required.
func PostingBaseDirectory ¶
func PostingBaseDirectory() string
PostingBaseDirectory returns the base directory used for storing articles/postings.
func PostingCount ¶ added in v0.10.1
func PostingCount() (rCount uint32)
PostingCount returns the number of postings currently available.
In case of I/O errors the return value will be `-1`.
func PrepareLinkScreenshots ¶ added in v0.18.0
func PrepareLinkScreenshots(aPosting *TPosting)
PrepareLinkScreenshots updates the external link(s) in `aPosting` to include page screenshot image(s) (if available).
`aPosting` The posting the text of which is going to be processed.
func ReadHashlist ¶ added in v0.9.0
ReadHashlist reads all postings to (re-)build the list of #hashtags/@mentions disregarding any pre-existing list.
`aList` The list of #hashtags/@mentions to build.
func RemoveIDTags ¶
RemoveIDTags removes `aID` from `aList's` items.
`aList` The hashlist to update. `aID` The ID of the posting to remove.
func RemovePageScreenshots ¶ added in v0.18.0
func RemovePageScreenshots(aPosting *TPosting)
RemovePageScreenshots deletes the images used in `aPosting`.
`aPosting` The posting the image(s) of which are going to be deleted.
func RenameIDTags ¶
RenameIDTags renames all references of `aOldID` to `aNewID`.
`aList` The hashlist to update. `aOldID` The posting's old ID. `aNewID` The posting's new ID.
func ReplaceTag ¶
ReplaceTag replaces the #tags/@mentions in `aList`.
`aList` The hashlist to update. `aSearchTag` The old #tag/@mention to find. `aReplaceTag` The new #tag/@mention to use.
func SetPostingBaseDirectory ¶
func SetPostingBaseDirectory(aBaseDir string)
SetPostingBaseDirectory sets the base directory used for storing articles/postings.
`aBaseDir` The base directory to use for storing articles/postings.
func URLparts ¶
URLparts returns two parts: `rDir` holds the base-directory of `aURL`, `rPath` holds the remaining part of `aURL`.
Depending on the actual value of `aURL` both return values may be empty or both may be filled; none of both will hold a leading slash.
func UpdateScreenshots ¶ added in v0.18.0
func UpdateScreenshots(aPostingBaseDir string)
UpdateScreenshots starts the process to update the screenshot images in all postings.
`aPostingBaseDir` The base directory used for storing
articles/postings.
func UpdateTags ¶
UpdateTags updates the #hashtag/@mention references of `aPosting`.
`aList` The hashlist to update. `aPosting` The new posting to process.
func UserAdd ¶ added in v0.17.0
func UserAdd(aUser, aFilename string)
UserAdd reads a password for `aUser` from the commandline and adds it to `aFilename`.
NOTE: This function does not return but terminates the program with error code `0` (zero) if successful, or `1` (one) otherwise.
`aUser` The username to add to the password file. `aFilename` The name of the password file to use.
func UserCheck ¶ added in v0.17.0
func UserCheck(aUser, aFilename string)
UserCheck reads a password for `aUser` from the commandline and compares it with the one stored in `aFilename`.
NOTE: This function does not return but terminates the program with error code `0` (zero) if successful, or `1` (one) otherwise.
`aUser` The username to check in the password file. `aFilename` The name of the password file to use.
func UserDelete ¶ added in v0.17.0
func UserDelete(aUser, aFilename string)
UserDelete removes the entry for `aUser` from the password list `aFilename`.
NOTE: This function does not return but terminates the program with error code `0` (zero) if successful, or `1` (one) otherwise.
`aUser` The username to remove from the password file. `aFilename` The name of the password file to use.
func UserList ¶ added in v0.17.0
func UserList(aFilename string)
UserList reads `aFilename` and lists all users stored in there.
NOTE: This function does not return but terminates the program with error code `0` (zero) if successful, or `1` (one) otherwise.
`aFilename` The name of the password file to use.
func UserUpdate ¶ added in v0.17.0
func UserUpdate(aUser, aFilename string)
UserUpdate reads a password for `aUser` from the commandline and updates the entry in the password list `aFilename`.
NOTE: This function does not return but terminates the program with error code `0` (zero) if successful, or `1` (one) otherwise.
`aUser` The username to remove from the password file.
`aFilename` The name of the password file to use.
Types ¶
type TAppArgs ¶ added in v0.17.0
type TAppArgs struct { AccessLog string // (optional) name of page access logfile Addr string // listen address ("1.2.3.4:5678") BlogName string // name/description of this blog CertKey string // TLS certificate key CertPem string // private TLS certificate DataDir string // base directory of application's data ErrorLog string // (optional) name of page error logfile GZip bool // send compressed data to remote browser HashFile string // file with hashtag/mention database // Intl string // path/filename of the localisation file Lang string // default GUI language LogStack bool // log stack trace in case of errors MaxFileSize int64 // max. upload file size Name string // name of the actual program PostAdd bool // whether to write a posting from commandline PostFile string // name of file to post Realm string // host/domain to secure by BasicAuth Screenshot bool // whether to use page screenshots or not Theme string // `dark` or `light` display theme UserAdd string // username to add to password list UserCheck string // username to check in password list UserDelete string // username to delete from password list UserFile string // (optional) name of page access logfile UserList bool // print out a list of current users UserUpdate string // username to update in password list // contains filtered or unexported fields }
TAppArgs Collection of commandline arguments and INI values.
var ( // AppArgs holds the commandline arguments and INI values. // // This structure should be considered R/O after it was // set up by a call to `InitConfig()`. AppArgs TAppArgs )
type TPageHandler ¶
type TPageHandler struct {
// contains filtered or unexported fields
}
TPageHandler provides the handling of HTTP request/response.
func NewPageHandler ¶
func NewPageHandler() (*TPageHandler, error)
NewPageHandler returns a new `TPageHandler` instance.
The returned object implements the `errorhandler.TErrorPager`, `http.Handler`, `and `passlist.TAuthDecider` interfaces.
func (*TPageHandler) GetErrorPage ¶
func (ph *TPageHandler) GetErrorPage(aData []byte, aStatus int) []byte
GetErrorPage returns an error page for `aStatus`, implementing the `TErrorPager` interface.
func (*TPageHandler) Len ¶
func (ph *TPageHandler) Len() int
Len returns the length of the internal views list.
func (*TPageHandler) NeedAuthentication ¶
func (ph *TPageHandler) NeedAuthentication(aRequest *http.Request) bool
NeedAuthentication returns `true` if authentication is needed, or `false` otherwise.
`aRequest` is the request to check.
func (*TPageHandler) ServeHTTP ¶
func (ph *TPageHandler) ServeHTTP(aWriter http.ResponseWriter, aRequest *http.Request)
ServeHTTP handles the incoming HTTP requests.
type TPostList ¶
type TPostList []TPosting
TPostList is a list of postings to be injected into a template/view.
func NewPostList ¶
func NewPostList() *TPostList
NewPostList returns a new (empty) TPostList instance.
func SearchPostings ¶
SearchPostings traverses the directories holding the postings looking for `aText` in all article files.
The returned `TPostList` can be empty because (a) `aText` could not be compiled into a regular expression, (b) no files to search were found, or (c) no files matched `aText`.
`aText` is the text to look for in the postings.
func (*TPostList) Add ¶
Add appends `aPosting` to the list.
`aPosting` contains the actual posting's text.
func (*TPostList) Delete ¶
Delete removes `aPosting` from the list, returning the (possibly modified) list and whether the operation war successful.
`aPosting` is the posting o remove from this list.
func (*TPostList) Index ¶
Index returns the 0-based list index of `aPosting`. In case `aPosting` was not found in list the return value will be `-1`.
`aPosting` is the posting to lookup in this list.
func (*TPostList) IsSorted ¶
IsSorted returns `true` if the list is sorted (in descending order), or `false` otherwise.
func (*TPostList) Month ¶
Month adds all postings of `aMonth` to the list.
`aYear` the year to lookup; if `0` (zero) the current year
is used.
`aMonth` the year's month to lookup; if `0` (zero) the
current month is used.
func (*TPostList) Newest ¶
Newest adds the last `aNumber` of postings to the list.
The resulting list is sorted in descending order (newest first) with at most `aNumber` posts.
`aNumber` The number of articles to show. `aStart` The start number to use.
func (*TPostList) Sort ¶
Sort returns the list sorted by posting IDs (i.e. date/time) in descending order.
type TPosting ¶
type TPosting struct {
// contains filtered or unexported fields
}
TPosting is a single article/posting..
func NewPosting ¶
NewPosting returns a new posting structure with an empty article text.
`aID` if an empty string the `NewID()` function is called
to provide a new article ID.
func (*TPosting) After ¶
After reports whether this posting is younger than the one identified by `aID`.
`aID` is the ID of another posting to compare.
func (*TPosting) Before ¶
Before reports whether this posting is older than the one identified by `aID`.
`aID` is the ID of another posting to compare.
func (*TPosting) Clear ¶
Clear resets the internal fields to their respective zero values.
This method does NOT remove the file (if any) associated with this posting/article; for that call the `Delete()` method.
func (*TPosting) Delete ¶
Delete removes the posting/article from the filesystem returning a possible I/O error.
This method does NOT empty the markdown text of the object; for that call the `Clear()` method.
func (*TPosting) Equal ¶
Equal reports whether this posting is of the same time as `aID`.
`aID` The ID of the posting to compare with this one.
func (*TPosting) ID ¶
ID returns the article's identifier.
The identifier is based on the article's creation time and given in hexadecimal notation.
This method allows the template to validate and use the placeholder `.ID`
func (*TPosting) LastModified ¶ added in v0.17.5
LastModified returns the last-modified date/time of the posting.
func (*TPosting) Len ¶
Len returns the current length of the posting's Markdown text.
If the markup is not already in memory this methods calls `TPosting.Load()` to read the text data from the filesystem.
func (*TPosting) Markdown ¶
Markdown returns the Markdown of this article.
If the markup is not already in memory this methods calls `TPosting.Load()` to read the text data from the filesystem.
func (*TPosting) PathFileName ¶
PathFileName returns the article's complete path-/filename.
func (*TPosting) Set ¶
Set assigns the article's Markdown text.
`aMarkdown` is the actual Markdown text of the article to assign.
func (*TPosting) Store ¶
Store writes the article's Markdown to disk returning the number of bytes written and a possible I/O error.
The file is created on disk with mode `0640` (`-rw-r-----`).
type TView ¶
type TView struct {
// contains filtered or unexported fields
}
TView combines a template and its logical name.
func NewView ¶
NewView returns a new `TView` with `aName`.
`aBaseDir` is the path to the directory storing the template files. `aName` is the name of the template file providing the page's main
body without the filename extension (i.e. w/o `.gohtml`). `aName` serves as both the main template's name as well as the view's name.
func (*TView) Render ¶
func (v *TView) Render(aWriter http.ResponseWriter, aData *TemplateData) error
Render executes the template using the TView's properties.
`aWriter` is a http.ResponseWriter, or e.g. `os.Stdout` in console apps.
`aData` is a list of data to be injected into the template.
If an error occurs executing the template or writing its output, execution stops, and the method returns without writing anything to the output `aWriter`.
func (*TView) RenderedPage ¶
func (v *TView) RenderedPage(aData *TemplateData) ([]byte, error)
RenderedPage returns the rendered template/page and a possible Error executing the template.
`aData` is a list of data to be injected into the template.
type TViewList ¶
type TViewList tViewList
TViewList is a list of `TView` instances (to be used as a template pool).
func NewViewList ¶
func NewViewList() *TViewList
NewViewList returns a new (empty) `TViewList` instance.
func (*TViewList) Add ¶
Add appends `aView` to the list.
`aView` is the view to add to this list.
The view's name (as specified in the `NewView()` function call) is used as the view's key in this list.
func (*TViewList) Get ¶
Get returns the view with `aName`.
`aName` is the name (key) of the `TView` object to retrieve.
If `aName` doesn't exist, the return value is `nil`. The second value (ok) is a `bool` that is `true` if `aName` exists in the list, and `false` if not.
func (*TViewList) Render ¶
func (vl *TViewList) Render(aName string, aWriter http.ResponseWriter, aData *TemplateData) error
Render executes the template with the key `aName`.
`aName` is the name of the template/view to use.
`aWriter` is a `http.ResponseWriter` to handle the executed template.
`aData` is a list of data to be injected into the template.
If an error occurs executing the template or writing its output, execution stops, and the method returns without writing anything to the output `aWriter`.
func (*TViewList) RenderedPage ¶
func (vl *TViewList) RenderedPage(aName string, aData *TemplateData) ([]byte, error)
RenderedPage returns the rendered template/page with the key `aName`.
`aName` is the name of the template/view to use.
`aData` is a list of data to be injected into the template.
type TemplateData ¶ added in v0.11.1
type TemplateData map[string]interface{}
TemplateData is a list of values to be injected into a template.
func NewTemplateData ¶ added in v0.11.1
func NewTemplateData() *TemplateData
NewTemplateData returns a new (empty) `TDataList` instance.
func (TemplateData) Get ¶ added in v0.17.2
func (dl TemplateData) Get(aKey string) (rValue interface{}, rOK bool)
Get returns the value associated with `aKey` and `true`. If `aKey` is not present in the list then the `bool` return value will be `false`.
`aKey` The value's identifier (as used as placeholder in the template).
func (*TemplateData) Set ¶ added in v0.11.1
func (dl *TemplateData) Set(aKey string, aValue interface{}) *TemplateData
Set inserts `aValue` identified by `aKey` to the list.
If there's already a list entry with `aKey` its current value gets replaced by `aValue`.
`aKey` The value's identifier (as used as placeholder in the template). `aValue` The data entry's value.