Comments (5)
I think I have found the cause of the issue.
The way I have implemented the following function
fn append_article_to_toml(&self, path: &Path) -> Result<()> {
// Article zine.toml file must exist
if !path.exists() {
Err(anyhow::anyhow!("Issue toml file does not already exists"))?
};
let mut file = std::fs::OpenOptions::new().append(true).open(&path)?;
let toml_str = toml::to_string(&self)?;
// Code fix as the section does not appear to be added by default.
file.write_all("[[article]]\n".as_bytes())?;
// This is the problem code is the line directly.
// I am adding this as it is for appending. But it breaks the toml parser in this test case.
file.write_all(toml_str.as_bytes())?;
Ok(())
}
from zine.
Follow up question
Is there a special reason that you use
#[serde(skip_serializing, default)]
on
pub struct Issue {}
With this code my test case for has to be written as
#[test]
fn test_append_article_to_issue() {
let mut issue = Issue::default();
let article = Article::new();
let article2 = Article::new().set_title("my second article").finalize();
issue.articles.push(article);
issue.articles.push(article2);
let mut toml_str = toml::to_string(&issue).unwrap();
// if the skip can be removed the following for loop is not required and the complete
// toml file can be written in a single function call
for article in &issue.articles {
toml_str.push_str("[[article]]\n");
toml_str.push_str(toml::to_string::<Article>(&article).unwrap().as_str());
}
let issue_from_toml: Issue = toml::from_str(&toml_str).unwrap();
assert_eq!(issue.slug, issue_from_toml.slug);
assert_eq!(issue.articles[0].meta.file, "Give-this-file-a-name");
assert_eq!(
issue.articles[0].meta.file,
issue_from_toml.articles[0].meta.file
);
assert_eq!(issue.articles[1].meta.file, "my-second-article");
assert_eq!(
issue.articles[1].meta.file,
issue_from_toml.articles[1].meta.file
);
}
What are your thoughts @Folyd
from zine.
Do you mean this?
Lines 29 to 35 in c3e514b
I have added a comment already, the main reason is we'll include the issue
entity when render article, we skip articles
to avoid unnecessary serialization, see:
Lines 108 to 127 in c3e514b
from zine.
I might be missing something. But I don't think you are actually getting any benefit from this approach. I think it is actually creating more code. Doing this way means you have to manage [[article]]
directly in code. See my code segment above.
This means you need to ensure that articles are added to the end of the issue's toml file using your own code logic. But without skip
toml will handle it automatically.
The toml for an issue will always contain at least one article. And if it does not and the Vec<Article>
is empty. Toml will correctly skip it by default.
from zine.
No longer needed.
from zine.
Related Issues (20)
- Fix mobile UI messy HOT 5
- Support all zine entity data access in external template
- Fix invalid date panic HOT 1
- Fix mobile UI messy - Author page HOT 2
- Add issue article to RSS feed
- Discussion: zine.toml for [Site] logo data field HOT 2
- Replace issue's zine.toml with front matter
- Add article list page
- Clippy running on included crates. HOT 2
- Add translation articles into sitemap.xml
- Show help for new website
- Handle "Address already in use" without panicking
- Remove unused dependency: http-body
- Support dark theme
- Support `team` account
- zine v0.13.0 reports error for basic `quote` block HOT 2
- Support topic link
- Zine V0.14.0 / Panic on Start / Using master rustmagazine HOT 1
- content didn't build when build finished HOT 3
- Convert TOC into a div and place it at the top or right-hand side? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from zine.