Skip to content

Commit

Permalink
updated upgrade plugin post
Browse files Browse the repository at this point in the history
  • Loading branch information
matryer committed Mar 13, 2021
1 parent f9a97a7 commit c0f01b2
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 34 deletions.
37 changes: 30 additions & 7 deletions tools/bloggen/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package main

import (
"bufio"
"bytes"
"context"
_ "embed"
"encoding/json"
Expand Down Expand Up @@ -63,7 +65,8 @@ func run(ctx context.Context, args []string) error {
filename := filepath.Base(path)
filename = strings.ToLower(filename[:len(filename)-2] + "html")
dest = filepath.Join(destFolder, filepath.Dir(rel), filename)
err := g.processMarkdownFile(ctx, dest, path)
destFilename := filepath.Join(filepath.Dir(rel), filename)
err := g.processMarkdownFile(ctx, destFilename, dest, path)
if err != nil {
return errors.Wrap(err, path)
}
Expand All @@ -78,7 +81,6 @@ func run(ctx context.Context, args []string) error {
if err != nil {
return err
}

return nil
}

Expand Down Expand Up @@ -118,11 +120,26 @@ func newGenerator() (*generator, error) {
return g, nil
}

func (g *generator) processMarkdownFile(ctx context.Context, dest, src string) error {
func (g *generator) processMarkdownFile(ctx context.Context, path, dest, src string) error {
b, err := os.ReadFile(src)
if err != nil {
return err
}
firstLine := string(bytes.Split(b, []byte("\n"))[0])

// find the first image
var imagePath string
s := bufio.NewScanner(bytes.NewReader(b))
for s.Scan() {
line := strings.TrimSpace(s.Text())
if strings.HasPrefix(line, "![") {
imagePath = strings.Split(line, "](")[1]
imagePath = strings.TrimSuffix(imagePath, ")")
imagePath = filepath.Join(filepath.Dir(path), imagePath)
imagePath = "https://xbarapp.com/docs/" + imagePath
break
}
}
html := markdown.ToHTML(b, nil, nil)
err = os.MkdirAll(filepath.Dir(dest), 0777)
if err != nil {
Expand All @@ -142,15 +159,21 @@ func (g *generator) processMarkdownFile(ctx context.Context, dest, src string) e
CurrentCategoryPath string
Categories map[string]metadata.Category

Title string
HTML template.HTML
Path string
Title string
Desc string
ImageURL string
HTML template.HTML
}{
Version: version,
LastUpdatedFormatted: time.Now().Format(time.RFC822),
Categories: g.categories,

Title: title,
HTML: template.HTML(html),
Path: path,
Title: title,
Desc: firstLine,
ImageURL: imagePath,
HTML: template.HTML(html),
}
err = g.template.ExecuteTemplate(f, "_main", pagedata)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,28 @@
Plugin authors are upgrading their plugins to use new xbar features.
xbar (the BitBar reboot) has shipped, and you might want to upgrade your BitBar plugin.

# Your plugin already works
Your BitBar plugin will run in xbar without any changes. However, there are a few tweaks you should make and one or two shiny new features to look at.

Your BitBar plugin works the same in xbar without any changes.
# What's new in xbar?

# But you should make some tweaks
1. Update your metadata - change `<bitbar.*>` tags to `<xbar.*>`
1. Use the `shell` parameter instead of `bash`
1. There is now no limit to the number of `paramN` parameters you can use
1. Use variables (new feature) instead of asking users to edit your scripts
1. Add keyboard shortcuts (new feature) to make your plugins even easier to use

* The `bash` parameter is now `shell`
* There is now no limit to the number of `paramN` parameters you can use
## Variables

Instead of asking users to edit your plugin script in order to configure the script, xbar introduces Variables.

# Plus, there are new features
![Screenshot showing an xbar plugin with variables](xbar-plugin-with-variables.png)

xbar brings a few new features that you may like to use in your plugin.
Variables are defined in your plugin's metadata. The xbar UI lets users configure the values without editing your script.

To make it work:

1. Add the `xbar.var` metadata to your plugin code (read the [Metadata documentation](https://github.com/matryer/xbar#metadata))
1. Remove any previous variables
1. Get the values by using environment variables

## Keyboard shortcuts

Expand All @@ -25,20 +36,6 @@ Let's go | key=shift+g | href=https://xbarapp.com/

You can specify a range of modifiers and special keys, for a full list check out the [Parameters documentation](https://github.com/matryer/xbar#parameters).

## Variables

Instead of asking users to edit your plugin script in order to configure the script, xbar introduces Variables.

![Screenshot showing an xbar plugin with variables](xbar-plugin-with-variables.png)

Variables are defined in your plugin's metadata. The xbar UI lets users configure the values without editing your script.

To make it work:

1. Add the `xbar.var` metadata to your plugin code (read the [Metadata documentation](https://github.com/matryer/xbar#metadata))
1. Remove any previous variables
1. Get the values by using environment variables

# Please try xbar, and report any issues

xbar is still brand new, so please help us reach a full release by reporting any issues you find.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit c0f01b2

Please sign in to comment.