Skip to content

Commit

Permalink
Added Feeder News feed for all users. So sorry for modifying everyone…
Browse files Browse the repository at this point in the history
…'s subscriptions! It only happens once for each user. Feel free to delete it if you don't want it.
  • Loading branch information
spacecowboy committed Jun 19, 2023
1 parent 5d85cc4 commit 838c8e6
Show file tree
Hide file tree
Showing 6 changed files with 382 additions and 11 deletions.
9 changes: 1 addition & 8 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -1252,7 +1252,7 @@ bruh (1):
mm4c (1):
* [6fe26dc0] Updated Dutch translation using Weblate

# 2.1.0
# 2.1.0-1
Jonas Kalderstam (19):
* [24c0c8fd] Implemented multi device sync
* [211b1281] Fixed spaces getting replaced by + in feed titles
Expand Down Expand Up @@ -1396,13 +1396,6 @@ zmni (1):
Éfrit (1):
* [5959c512] Updated French translation using Weblate

# 2.1.0-beta.1
Jonas Kalderstam (1):
* [24c0c8fd] Implemented multi device sync

Meiru (1):
* [9957d68b] Updated Japanese translation using Weblate

# 2.0.14
Jonas Kalderstam (1):
* [90e8048c] Fixed spaces getting replaced by + in feed titles
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import com.nononsenseapps.feeder.db.room.RemoteFeed
import com.nononsenseapps.feeder.db.room.SyncDevice
import com.nononsenseapps.feeder.db.room.SyncRemote
import com.nononsenseapps.feeder.model.workmanager.SyncServiceSendReadWorker
import com.nononsenseapps.feeder.model.workmanager.requestFeedSync
import com.nononsenseapps.feeder.sync.SyncRestClient
import com.nononsenseapps.feeder.ui.compose.feed.FeedListItem
import com.nononsenseapps.feeder.ui.compose.navdrawer.DrawerItemWithUnreadCount
Expand Down Expand Up @@ -60,6 +61,28 @@ class Repository(override val di: DI) : DIAware {
private val syncClient: SyncRestClient by instance()
private val workManager: WorkManager by instance()

init {
addFeederNewsIfInitialStart()
}

private fun addFeederNewsIfInitialStart() {
if (!settingsStore.addedFeederNews.value) {
applicationCoroutineScope.launch {
val feedId = feedStore.upsertFeed(
Feed(
title = "Feeder News",
url = URL("https://news.nononsenseapps.com/index.atom"),
),
)
settingsStore.setAddedFeederNews(true)
requestFeedSync(
di = di,
feedId = feedId,
)
}
}
}

val showOnlyUnread: StateFlow<Boolean> = settingsStore.showOnlyUnread
fun setShowOnlyUnread(value: Boolean) = settingsStore.setShowOnlyUnread(value)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ class SettingsStore(override val di: DI) : DIAware {
private val sp: SharedPreferences by instance()
private val blocklistDao: BlocklistDao by instance()

private val _addedFeederNews = MutableStateFlow(sp.getBoolean(PREF_ADDED_FEEDER_NEWS, false))
val addedFeederNews: StateFlow<Boolean> = _addedFeederNews.asStateFlow()
fun setAddedFeederNews(value: Boolean) {
sp.edit().putBoolean(PREF_ADDED_FEEDER_NEWS, value).apply()
_addedFeederNews.value = value
}

private val _showOnlyUnread = MutableStateFlow(sp.getBoolean(PREF_SHOW_ONLY_UNREAD, true))
val showOnlyUnread: StateFlow<Boolean> = _showOnlyUnread.asStateFlow()
fun setShowOnlyUnread(value: Boolean) {
Expand Down Expand Up @@ -382,9 +389,9 @@ const val PREF_WELCOME_DONE = "pref_welcome_done"
const val PREF_SHOW_ONLY_UNREAD = "pref_show_only_unread"

/**
* Boolean indicating if only bookmarked items should be shown
* Boolean indicating if Feeder News feed has been added or not
*/
const val PREF_SHOW_ONLY_BOOKMARKED = "pref_show_only_bookmarked"
const val PREF_ADDED_FEEDER_NEWS = "pref_added_feeder_news"

/**
* These indicate which fragment to open by default
Expand Down
22 changes: 21 additions & 1 deletion release.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ then
fi

CL="# ${NEXT_VERSION}
$(git shortlog -w76,2,9 --format='* [%h] %s' "${CURRENT_VERSION}..HEAD")
$(git shortlog -w76,2,9 --max-parents=1 --format='* [%h] %s' "${CURRENT_VERSION}..HEAD")
"

tmpfile="$(mktemp)"
Expand Down Expand Up @@ -100,3 +100,23 @@ then
fi

git checkout app/src/main/res fastlane/metadata/android

read -r -p "Post to feed? [y/N] " response
if [[ "$response" =~ ^[yY]$ ]]
then
scripts/changelog-to-hugo.main.kts ../feeder-news/content/posts/ "${NEXT_VERSION}"
pushd ../feeder-news
git add content/posts/
git diff --staged
git commit -m "Released ${NEXT_VERSION}"
popd
fi

read -r -p "Push the lot? [y/N] " response
if [[ "$response" =~ ^[yY]$ ]]
then
git push --follow-tags
pushd ../feeder-news
git push
popd
fi
153 changes: 153 additions & 0 deletions scripts/changelog-to-hugo.main.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
#!/usr/bin/env kotlin
@file:DependsOn("org.jetbrains:markdown-jvm:0.4.1")
@file:DependsOn("net.pwall.mustache:kotlin-mustache:0.10")

import java.io.File
import java.util.concurrent.TimeUnit
import net.pwall.mustache.parser.Parser
import org.intellij.markdown.MarkdownElementTypes
import org.intellij.markdown.ast.ASTNode
import org.intellij.markdown.flavours.commonmark.CommonMarkFlavourDescriptor
import org.intellij.markdown.html.HtmlGenerator
import org.intellij.markdown.parser.MarkdownParser

val flavour = CommonMarkFlavourDescriptor()

data class ChangelogEntry(
val version: String,
val content: String,
) {
val timestamp: String
get() = "git log -1 --format=%aI $version".runCommand()

val title: String
get() = "$version released"
}

fun parseChangelog(): List<ChangelogEntry> {
val src = File("CHANGELOG.md").readText()
val parsedTree = MarkdownParser(flavour).buildMarkdownTreeFromString(src)
val entries = mutableListOf<ChangelogEntry>()
val sb = StringBuilder()

recurseMarkdown(
node = parsedTree,
src = src,
version = "",
sb = sb,
entries = entries,
)

return entries
}

fun recurseMarkdown(
node: ASTNode,
src: String,
version: String,
sb: StringBuilder,
entries: MutableList<ChangelogEntry>,
): String {
var newVersion = version
var ignoreContent = false
when (node.type) {
MarkdownElementTypes.MARKDOWN_FILE -> {
// Keep going directly
ignoreContent = true
}

MarkdownElementTypes.ATX_1 -> {
// Header marks boundary between entries
if (sb.isNotBlank()) {
entries.add(
ChangelogEntry(
version = newVersion,
content = sb.toString(),
),
)
sb.clear()
}
val textNode = node.children.last()
return src.slice(textNode.startOffset until textNode.endOffset).trim()
}
}

if (ignoreContent) {
for (child in node.children) {
newVersion = recurseMarkdown(
node = child,
src = src,
version = newVersion,
sb = sb,
entries = entries,
)
}
} else {
val content = src.slice(node.startOffset until node.endOffset)
sb.append(content)
}
return newVersion
}

fun generateHugoEntries(targetDir: File, entries: List<ChangelogEntry>) {
val hugoTemplateString = """
---
title: "{{title}}"
date: {{timestamp}}
draft: false
thumbnail: "feature.png"
---
{{&content}}
""".trimIndent()

println("${entries.size} entries")

val parser = Parser()
val hugoTemplate = parser.parse(hugoTemplateString)

entries.forEach { entry ->
val targetFile = targetDir.resolve("${entry.version}.md")
if (targetFile.isFile) {
if (!targetFile.delete()) {
error("Failed to delete existing file: $targetFile")
}
}
targetDir.resolve("${entry.version}.md").bufferedWriter().use { writer ->
writer.write(hugoTemplate.processToString(entry))
}
}
}

fun String.runCommand(): String {
val parts = this.split("\\s".toRegex())
val proc = ProcessBuilder(*parts.toTypedArray())
.directory(File("/home/jonas/workspace/feeder"))
.redirectOutput(ProcessBuilder.Redirect.PIPE)
.redirectError(ProcessBuilder.Redirect.PIPE)
.start()

proc.waitFor(2, TimeUnit.SECONDS)
return proc.inputStream.bufferedReader().readText().trim()
}

// $args

val targetDir = args.firstOrNull()
?.let { File(it) }
?: error("Expects target directory as first argument")

if (!targetDir.isDirectory) {
error("$targetDir does not exist or is not a directory!")
}

// To only generate a specific tag out of the changelog
val tag = args.getOrNull(1)

val entries = parseChangelog()

generateHugoEntries(
targetDir = targetDir,
entries = entries.filter {
tag == null || it.version == tag
},
)
Loading

0 comments on commit 838c8e6

Please sign in to comment.