diff --git a/assets/scripts/components/screens/AtelierPages.svelte b/assets/scripts/components/screens/AtelierPages.svelte
index 2dcc0233..69dfa4bf 100644
--- a/assets/scripts/components/screens/AtelierPages.svelte
+++ b/assets/scripts/components/screens/AtelierPages.svelte
@@ -8,7 +8,9 @@
pages: any[] | undefined
showArticles: boolean | undefined
currentRepository: ScribouilliGitRepo
- conflict: ScribouilliState["conflict"]
+ conflict: ScribouilliState['conflict']
+ blogEnabled: boolean
+ onBlogToggle: (activated: boolean) => void
}
let {
@@ -16,8 +18,10 @@
pages,
showArticles,
currentRepository,
- conflict
- }: Props = $props();
+ conflict,
+ blogEnabled,
+ onBlogToggle,
+ }: Props = $props()
diff --git a/assets/scripts/routes/atelier-list-pages.ts b/assets/scripts/routes/atelier-list-pages.ts
index 476a659c..904fd48e 100644
--- a/assets/scripts/routes/atelier-list-pages.ts
+++ b/assets/scripts/routes/atelier-list-pages.ts
@@ -1,21 +1,77 @@
import { replaceComponent } from '../routeComponentLifeCycle.svelte'
import { setCurrentRepositoryFromQuerystring } from '../actions/current-repository.ts'
import AtelierPages from '../components/screens/AtelierPages.svelte'
-import { showArticles } from '../actions/article'
+import { blogIndex, showArticles } from '../actions/article'
import { Context } from 'page'
import type { ScribouilliState } from '../store.ts'
+import { writeFileAndCommit, deleteFileAndCommit } from '../actions/file'
+import {
+ getCurrentRepoPages,
+ getCurrentRepoArticles,
+} from '../actions/current-repository.ts'
+import { handleErrors } from '../utils.ts'
+
+const blogMdContent = `---
+layout: page
+title: Articles
+permalink: /articles/
+blog_index: true
+---
+
+
+{% for post in site.posts %}
+
+
+ {{ post.title }}
+
+
+ Lire l'article ➞
+
+
+{% endfor %}
+`
const mapStateToProps = (state: ScribouilliState) => {
- if (!state.currentRepository) {
+ const blogFile = blogIndex(state)
+
+ const { currentRepository, gitAgent } = state
+ if (!gitAgent) {
+ throw new TypeError('gitAgent is undefined')
+ }
+ if (!currentRepository) {
throw new TypeError('currentRepository is undefined')
}
return {
pages: state.pages,
buildStatus: state.buildStatus,
- currentRepository: state.currentRepository,
+ currentRepository: currentRepository,
showArticles: showArticles(state),
conflict: state.conflict,
+ blogEnabled: blogFile !== undefined,
+ onBlogToggle: async (activated: boolean): Promise => {
+ try {
+ if (activated) {
+ await writeFileAndCommit(
+ 'blog.md',
+ blogMdContent,
+ 'Activation du blog',
+ )
+ } else {
+ const blogPath = blogIndex(state) as string
+ await deleteFileAndCommit(blogPath, 'Désactivation du blog')
+ }
+ await getCurrentRepoArticles()
+ await getCurrentRepoPages()
+
+ gitAgent.safePush()
+ } catch (msg: any) {
+ handleErrors(msg)
+ }
+ },
}
}
diff --git a/assets/scripts/routes/settings.ts b/assets/scripts/routes/settings.ts
index 8a190f81..95d48f7c 100644
--- a/assets/scripts/routes/settings.ts
+++ b/assets/scripts/routes/settings.ts
@@ -3,47 +3,17 @@ import { replaceComponent } from '../routeComponentLifeCycle.svelte'
import store, { type ScribouilliState } from '../store'
import {
getCurrentRepoPages,
- getCurrentRepoArticles,
setCurrentRepositoryFromQuerystring,
saveCustomCSS,
} from '../actions/current-repository.ts'
import { handleErrors } from '../utils'
import Settings from '../components/screens/Settings.svelte'
-import { writeFileAndCommit, deleteFileAndCommit } from '../actions/file'
-import { blogIndex, showArticles } from '../actions/article'
+import { showArticles } from '../actions/article'
import { Context } from 'page'
-const blogMdContent = `---
-layout: page
-title: Articles
-permalink: /articles/
-blog_index: true
----
-
-
-{% for post in site.posts %}
-
-
- {{ post.title }}
-
-
- Lire l'article ➞
-
-
-{% endfor %}
-`
-
function mapStateToProps(state: ScribouilliState) {
- const blogFile = blogIndex(state)
// TODO: this should probably be `state` not `store.state`
- const { currentRepository, gitAgent } = store.state
-
- if (!gitAgent) {
- throw new TypeError('gitAgent is undefined')
- }
+ const { currentRepository } = store.state
if (!currentRepository) {
throw new TypeError('currentRepository is undefined')
@@ -53,32 +23,11 @@ function mapStateToProps(state: ScribouilliState) {
buildStatus: state.buildStatus,
theme: state.theme,
deleteRepositoryUrl: `${currentRepository.publicRepositoryURL}/settings#danger-zone`,
- blogEnabled: blogFile !== undefined,
showArticles: showArticles(state),
currentRepository: state.currentRepository,
onUpdateTheme: (theme: { css: string }): void => {
saveCustomCSS(theme.css).catch(handleErrors)
},
- onToggleBlog: async (activated: boolean): Promise => {
- try {
- if (activated) {
- await writeFileAndCommit(
- 'blog.md',
- blogMdContent,
- 'Activation du blog',
- )
- } else {
- await deleteFileAndCommit('blog.md', 'Désactivation du blog')
- }
- await getCurrentRepoArticles()
- await getCurrentRepoPages()
-
- gitAgent.safePush()
- } catch (msg) {
- //@ts-ignore
- handleErrors(msg)
- }
- },
}
}