sshblogger

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 10, 2024 License: MIT Imports: 6 Imported by: 0

README

SSHblogger: a Bubbletea Component for Markdown Blogs in the Terminal

Motivation

There's a list bubble component implemented here and glamour renders markdown in the terminal.

Let's put them together and make a blog!

Quickstart for your terminal

import (
    "fmt"
    "os"

    tea "github.com/charmbracelet/bubbletea"
    "github.com/charmbracelet/lipgloss"
    "gitlab.com/rdubwwily/sshblogger"
)

m := NewBlogModel(sshblogger.DemoBlogItems, "Ryan's Blog!", 100, 25, 10, lipgloss.NewStyle())
p := tea.NewProgram(m)
if _, err := p.Run(); err != nil {
	fmt.Printf("Alas, there's been an error: %v", err)
	os.Exit(1)
}

How to use the component

Here's the new blog model function:
func NewBlogModel(getBlogItems func() []BlogItem, title string, width int, height int, markdownHeight int, liststyle lipgloss.Style) BlogModel {
    m := BlogModel{
        GetBlogItems: getBlogItems,
        List: list.New(
            []list.Item{},
            list.NewDefaultDelegate(),
            width,
            height,
        ),
        Width:            width,
        Height:           height,
        ListRenderer:     liststyle,
        MarkdownHeight:   markdownHeight,
        contentLineStart: 0,
        contentLineEnd:   markdownHeight - 1,
    }
    m.List.Title = title
    return m
}

Biggest thing is to supply a function that gives a list of blog items, which is turned into list items.

Check out an implementation of serving the blog over wish with a sqlite DB here

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertBlogItemsToListItems

func ConvertBlogItemsToListItems(blogItems []BlogItem) []list.Item

func GenerateLongItem

func GenerateLongItem() string

func RefreshBlogCommand

func RefreshBlogCommand() tea.Msg

Types

type BlogItem

type BlogItem struct {
	Id          int
	Title       string
	Description string
	Content     string
}

func DemoBlogItems

func DemoBlogItems() []BlogItem

type BlogModel

type BlogModel struct {
	List           list.Model
	BlogItems      []BlogItem
	BlogTitle      string
	GetBlogItems   func() []BlogItem
	IsViewing      bool
	CurrentContent []string
	Width          int
	Height         int
	ListRenderer   lipgloss.Style

	MarkdownHeight int
	// contains filtered or unexported fields
}

func NewBlogModel

func NewBlogModel(getBlogItems func() []BlogItem, title string, width int, height int, markdownHeight int, liststyle lipgloss.Style) BlogModel

func (BlogModel) Init

func (m BlogModel) Init() tea.Cmd

func (BlogModel) Update

func (m BlogModel) Update(msg tea.Msg) (tea.Model, tea.Cmd)

func (BlogModel) View

func (m BlogModel) View() string

type BlogResizeMsg

type BlogResizeMsg struct {
	// contains filtered or unexported fields
}

type RefreshBlogMsg

type RefreshBlogMsg struct{}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL