feat: clean up html readability; add autm. tag creation
This commit is contained in:
parent
3990fe013b
commit
42b5cb4413
4
.github/workflows/release.yml
vendored
4
.github/workflows/release.yml
vendored
@ -64,7 +64,7 @@ jobs:
|
|||||||
GOOS: ${{ env.OS }}
|
GOOS: ${{ env.OS }}
|
||||||
GOARCH: ${{ matrix.arch }}
|
GOARCH: ${{ matrix.arch }}
|
||||||
run: |
|
run: |
|
||||||
go build -ldflags "-X main.version=$(git describe --tags --abbrev=0)" -o fabric-${OS}-${{ matrix.arch }} .
|
go build -o fabric-${OS}-${{ matrix.arch }} .
|
||||||
|
|
||||||
- name: Build binary on Windows
|
- name: Build binary on Windows
|
||||||
if: matrix.os == 'windows-latest'
|
if: matrix.os == 'windows-latest'
|
||||||
@ -72,7 +72,7 @@ jobs:
|
|||||||
GOOS: windows
|
GOOS: windows
|
||||||
GOARCH: ${{ matrix.arch }}
|
GOARCH: ${{ matrix.arch }}
|
||||||
run: |
|
run: |
|
||||||
go build -ldflags "-X main.version=$(git describe --tags --abbrev=0)" -o fabric-windows-${{ matrix.arch }}.exe .
|
go build -o fabric-windows-${{ matrix.arch }}.exe .
|
||||||
|
|
||||||
- name: Upload build artifact
|
- name: Upload build artifact
|
||||||
if: matrix.os != 'windows-latest'
|
if: matrix.os != 'windows-latest'
|
||||||
|
@ -1,11 +1,9 @@
|
|||||||
name: Update Version File
|
name: Update Version and Create Tag
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- main # Or whichever branch you want to monitor
|
- main # Monitor the main branch
|
||||||
tags:
|
|
||||||
- '*' # Trigger on any new tag
|
|
||||||
|
|
||||||
permissions:
|
permissions:
|
||||||
contents: write # Ensure the workflow has write permissions
|
contents: write # Ensure the workflow has write permissions
|
||||||
@ -28,32 +26,43 @@ jobs:
|
|||||||
- name: Get the latest tag
|
- name: Get the latest tag
|
||||||
id: get_latest_tag
|
id: get_latest_tag
|
||||||
run: |
|
run: |
|
||||||
latest_tag=$(git describe --tags --abbrev=0)
|
latest_tag=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")
|
||||||
echo "Latest tag is: $latest_tag"
|
echo "Latest tag is: $latest_tag"
|
||||||
echo "::set-output name=tag::$latest_tag"
|
echo "::set-output name=tag::$latest_tag"
|
||||||
|
|
||||||
- name: Get the latest commit hash
|
- name: Increment minor version
|
||||||
id: get_commit_hash
|
id: increment_version
|
||||||
run: |
|
run: |
|
||||||
commit_hash=$(git rev-parse --short HEAD)
|
latest_tag=${{ steps.get_latest_tag.outputs.tag }}
|
||||||
echo "Commit hash is: $commit_hash"
|
IFS='.' read -r major minor patch <<<"${latest_tag#v}"
|
||||||
echo "::set-output name=commit_hash::$commit_hash"
|
new_minor=$((minor + 1))
|
||||||
|
new_tag="v${major}.${new_minor}.0"
|
||||||
|
echo "New tag is: $new_tag"
|
||||||
|
echo "::set-output name=new_tag::$new_tag"
|
||||||
|
|
||||||
- name: Update version.go file
|
- name: Update version.go file
|
||||||
run: |
|
run: |
|
||||||
latest_tag=${{ steps.get_latest_tag.outputs.tag }}
|
new_tag=${{ steps.increment_version.outputs.new_tag }}
|
||||||
commit_hash=${{ steps.get_commit_hash.outputs.commit_hash }}
|
commit_hash=$(git rev-parse --short HEAD)
|
||||||
echo "package main" > version.go
|
echo "package main" > version.go
|
||||||
echo "" >> version.go
|
echo "" >> version.go
|
||||||
echo "var version = \"${latest_tag}-${commit_hash}\"" >> version.go
|
echo "var version = \"${new_tag}-${commit_hash}\"" >> version.go
|
||||||
|
|
||||||
- name: Commit changes
|
- name: Commit changes
|
||||||
run: |
|
run: |
|
||||||
git add version.go
|
git add version.go
|
||||||
git commit -m "Update version to ${{ steps.get_latest_tag.outputs.tag }} and commit ${{ steps.get_commit_hash.outputs.commit_hash }}"
|
git commit -m "Update version to ${{ steps.increment_version.outputs.new_tag }} and commit $commit_hash"
|
||||||
|
|
||||||
- name: Push changes
|
- name: Push changes
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Use GITHUB_TOKEN to authenticate the push
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Use GITHUB_TOKEN to authenticate the push
|
||||||
run: |
|
run: |
|
||||||
git push origin main # Or the relevant branch
|
git push origin main # Push changes to the main branch
|
||||||
|
|
||||||
|
- name: Create a new tag
|
||||||
|
env:
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
run: |
|
||||||
|
new_tag=${{ steps.increment_version.outputs.new_tag }}
|
||||||
|
git tag $new_tag
|
||||||
|
git push origin $new_tag # Push the new tag
|
1
.gitignore
vendored
1
.gitignore
vendored
@ -11,6 +11,7 @@ __pycache__/
|
|||||||
|
|
||||||
# Distribution / packaging
|
# Distribution / packaging
|
||||||
.Python
|
.Python
|
||||||
|
.idea
|
||||||
build/
|
build/
|
||||||
develop-eggs/
|
develop-eggs/
|
||||||
dist/
|
dist/
|
||||||
|
@ -243,8 +243,8 @@ Application Options:
|
|||||||
-e, --seed= Seed to be used for LMM generation
|
-e, --seed= Seed to be used for LMM generation
|
||||||
-w, --wipecontext= Wipe context
|
-w, --wipecontext= Wipe context
|
||||||
-W, --wipesession= Wipe session
|
-W, --wipesession= Wipe session
|
||||||
|
--readability Convert HTML input into a clean, readable view
|
||||||
--dry-run Show what would be sent to the model without actually sending it
|
--dry-run Show what would be sent to the model without actually sending it
|
||||||
--readability Turn web page into a clean view
|
|
||||||
--version Print current version
|
--version Print current version
|
||||||
|
|
||||||
Help Options:
|
Help Options:
|
||||||
|
17
cli/cli.go
17
cli/cli.go
@ -2,6 +2,7 @@ package cli
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/danielmiessler/fabric/converter"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
@ -110,6 +111,14 @@ func Cli(version string) (message string, err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if currentFlags.HtmlReadability {
|
||||||
|
if msg, cleanErr := converter.HtmlReadability(currentFlags.Message); cleanErr != nil {
|
||||||
|
fmt.Println("use original input, because can't apply html readability", err)
|
||||||
|
} else {
|
||||||
|
currentFlags.Message = msg
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// if the interactive flag is set, run the interactive function
|
// if the interactive flag is set, run the interactive function
|
||||||
// if currentFlags.Interactive {
|
// if currentFlags.Interactive {
|
||||||
// interactive.Interactive()
|
// interactive.Interactive()
|
||||||
@ -193,14 +202,6 @@ func Cli(version string) (message string, err error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if currentFlags.HtmlReadability {
|
|
||||||
if msg, err := core.HtmlReadability(currentFlags.Message); err != nil {
|
|
||||||
fmt.Println("use readability parser msg err:", err)
|
|
||||||
} else {
|
|
||||||
currentFlags.Message = msg
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var chatter *core.Chatter
|
var chatter *core.Chatter
|
||||||
if chatter, err = fabric.GetChatter(currentFlags.Model, currentFlags.Stream, currentFlags.DryRun); err != nil {
|
if chatter, err = fabric.GetChatter(currentFlags.Model, currentFlags.Stream, currentFlags.DryRun); err != nil {
|
||||||
return
|
return
|
||||||
|
@ -46,8 +46,8 @@ type Flags struct {
|
|||||||
Seed int `short:"e" long:"seed" description:"Seed to be used for LMM generation"`
|
Seed int `short:"e" long:"seed" description:"Seed to be used for LMM generation"`
|
||||||
WipeContext string `short:"w" long:"wipecontext" description:"Wipe context"`
|
WipeContext string `short:"w" long:"wipecontext" description:"Wipe context"`
|
||||||
WipeSession string `short:"W" long:"wipesession" description:"Wipe session"`
|
WipeSession string `short:"W" long:"wipesession" description:"Wipe session"`
|
||||||
|
HtmlReadability bool `long:"readability" description:"Convert HTML input into a clean, readable view"`
|
||||||
DryRun bool `long:"dry-run" description:"Show what would be sent to the model without actually sending it"`
|
DryRun bool `long:"dry-run" description:"Show what would be sent to the model without actually sending it"`
|
||||||
HtmlReadability bool `long:"readability" description:"Turn web page into a clean view"`
|
|
||||||
Version bool `long:"version" description:"Print current version"`
|
Version bool `long:"version" description:"Print current version"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
25
converter/html_readability.go
Normal file
25
converter/html_readability.go
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
package converter
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"github.com/go-shiori/go-readability"
|
||||||
|
)
|
||||||
|
|
||||||
|
// HtmlReadability Convert HTML input into a clean, readable view
|
||||||
|
// args:
|
||||||
|
//
|
||||||
|
// html (string): full data of web page
|
||||||
|
//
|
||||||
|
// return:
|
||||||
|
//
|
||||||
|
// viewContent (string): html main content
|
||||||
|
// err (error): parser error
|
||||||
|
func HtmlReadability(html string) (ret string, err error) {
|
||||||
|
buf := bytes.NewBufferString(html)
|
||||||
|
var article readability.Article
|
||||||
|
if article, err = readability.FromReader(buf, nil); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
ret = article.TextContent
|
||||||
|
return
|
||||||
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package core
|
package converter
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
@ -1,27 +0,0 @@
|
|||||||
package core
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"fmt"
|
|
||||||
"github.com/go-shiori/go-readability"
|
|
||||||
)
|
|
||||||
|
|
||||||
// HtmlReadability Turn any web page into a clean view
|
|
||||||
// args:
|
|
||||||
//
|
|
||||||
// html (string): full data of web page
|
|
||||||
//
|
|
||||||
// return:
|
|
||||||
//
|
|
||||||
// viewContent (string): html main content
|
|
||||||
// err (error): parser error
|
|
||||||
func HtmlReadability(html string) (viewContent string, err error) {
|
|
||||||
buf := bytes.NewBufferString(html)
|
|
||||||
article, err := readability.FromReader(buf, nil)
|
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
fmt.Println("MAIN-CONTENT:", article.TextContent)
|
|
||||||
|
|
||||||
return article.TextContent, nil
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user