Skip to content

Commit

Permalink
add tests and update README
Browse files Browse the repository at this point in the history
  • Loading branch information
TimoKats committed Aug 31, 2024
1 parent 5e2d43b commit 62fe946
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 31 deletions.
20 changes: 13 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,7 @@
MDRSS is a markdown to RSS converter written in GO. With this tool, you can write articles in a local folder and have them automatically formatted to an RSS compliant XML file. As a result, you don't have to write articles on your website first and have them be read by an RSS reader. Moreover, MDRSS automatically takes care of publication dates, categories (next update), formatting, etc.

### Getting started
You can install the binary using `go install github.com/TimoKats/mdrss@latest` (make sure your GOPATH is set correctly!). After this you can add your configuration in `~/.mdrss/config.json`. This is a JSON file with a number of settings. You can use this template to setup your configuration. Note, the most recent update also allows users to specify their own config path, which you can define like so.

```shell
mdrss --config other/path/to/config update
```
You can install the binary using `go install github.com/TimoKats/mdrss@latest` (make sure your GOPATH is set correctly!). After this you can add your configuration in `~/.mdrss/config.json`. This is a JSON file with a number of settings. You can use this template to setup your configuration.

```JSON
{
Expand All @@ -19,7 +15,18 @@ mdrss --config other/path/to/config update
}
```

In your input folder, you can add an article by creating a `.md` file. **Note, if your filename is prefixed with `draft-` it will not be included in the RSS file**. Finally, you can type `mdrss ls` to view the articles ready for publishing and `mdrss update` to create the RSS feed. Note, the title of the RSS articles are based on markdown headers. E.g. format the first line of the markdown articles as so: `# this is a title`.
Note, the most recent update also allows users to specify their own config path, which you can define like so.
```shell
mdrss --config other/path/to/config update
```

In your input folder, you can add an article by creating a `.md` file. **Note, if your filename is prefixed with `draft-` it will not be included in the RSS file**. Finally, you can type `mdrss ls` to view the articles ready for publishing and `mdrss update` to create the RSS feed. Note, the title of the RSS articles are based on markdown headers. E.g. format the first line of the markdown articles as so: `# this is a title`.

Mdrss also supports the usage of RSS enclosures (relevant for podcasts). To create an enclosure link: create a regular markdown link to the audio file with the identifier as "audio/mpeg".

```markdown
[audio/mpeg](https://link.to.mp3/file.mp3)
```

### Publishing the RSS file
You can submit your RSS file to a public website, or put it somewhere easily available on a public drive, apache server, etc. Note, there is a chance I will make a function for this on my website so that people who can't host RSS feeds themselves can still publish their feeds. Please let me know if you're interested in such a service.
Expand All @@ -29,7 +36,6 @@ List of features that are on the planning. Feel free to send suggestions here.
* Display source code from markdown more correctly.
* For non textual RSS readers: render images.
* Ordered lists
* RSS enclosures for podcasts

### Why RSS?
* No ads/trackers/cookies.
Expand Down
32 changes: 9 additions & 23 deletions lib/filesize.go
Original file line number Diff line number Diff line change
@@ -1,51 +1,37 @@
package lib

import (
"strconv"
"unicode"
"strings"
"os/exec"
"os"
"errors"
)

func extractInt(text string) int {
func extractInt(text string) string {
filteredString := ""
for _, character := range text {
if unicode.IsDigit(character) {
filteredString += string(character)
}
}
integer, convErr := strconv.Atoi(filteredString)
if convErr != nil {
Error.Println(convErr)
return 1
if len(filteredString) == 0 {
return "1"
} else {
return integer
return filteredString
}
}

func FileSizeLocal(filename string) int {
fileInfo, fileErr := os.Stat(filename)
if fileErr != nil {
Error.Println(fileErr)
return 1
}
return int(fileInfo.Size())
}

func FileSizeUrl(url string) int {
func FileSizeUrl(url string) (string, error) {
cmd := exec.Command("curl", "-sIL", url)
cmdOutput, cmdErr := cmd.Output()
if cmdErr != nil {
Error.Println(cmdErr)
return 1
return "1", errors.New("Issues when running curl to get filesize.")
} else {
for _, line := range strings.Split(string(cmdOutput), "\n") {
if strings.Contains(line, "content-length") {
return extractInt(line)
return extractInt(line), nil
}
}
}
Error.Printf("No content-length found for %s", url)
return 1
return "1", errors.New("No content-length found for url")
}
8 changes: 7 additions & 1 deletion lib/markdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,13 @@ func convertMarkdownLink(text string, markdownLinks *regexp.Regexp) string {
}

func convertMarkdownEnclosure(text string, markdownLinks *regexp.Regexp) string {
return "<enclosure " + markdownLinks.ReplaceAllString(text, "url='$2' type='$1'") + " />"
url := markdownLinks.ReplaceAllString(text, "$2")
size, fileSizeErr := FileSizeUrl(url)
if fileSizeErr != nil {
Error.Println(fileSizeErr)
return ""
}
return "<enclosure " + markdownLinks.ReplaceAllString(text, "url='$2' type='$1' length='") + size + "' />"
}

func convertMarkdownList(text string) string {
Expand Down
18 changes: 18 additions & 0 deletions mdrss_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,24 @@ func TestConvertLinks(t *testing.T) {
}
}

func TestEnclosures(t *testing.T) {
got, fileSizeErr := mdrss.FileSizeUrl("https://file-examples.com/storage/fec2f2681466d1d67a0683d/2017/11/file_example_MP3_700KB.mp3")
want := "733645"
if got != want {
t.Errorf("got %v, wanted %v", got, want)
}
if fileSizeErr != nil {
t.Errorf("not good %v", fileSizeErr)
}
}

func TestFakeEnclosures(t *testing.T) {
_, fileSizeErr := mdrss.FileSizeUrl("hello.mp3")
if fileSizeErr == nil {
t.Errorf("Should give Error, but no.")
}
}

func TestBasics(t *testing.T) {
config := testConfig()
articles, _ := mdrss.GetArticles(config)
Expand Down

0 comments on commit 62fe946

Please sign in to comment.